This is my basic schema
type user{
name:string
category:[category]
}
type category
{
cname:string
userId:String
}
==============================
String triples=" :"+userName+" <name> “”+userName+"" .\n :"+userName+" <dgraph.type> “user” .\n" +
" :"+categoryName+" <cname> “”+categoryName+"" .\n"+
" :"+categoryName+" <dgraph.type> “category” .\n"+
" :"+categoryName+" <userId> “”+userName+"" .\n"+
" :"+userName+" <category> _:"+categoryName+" .\n";
i am trying to mutate the data to dgraph using
DgraphProto.Mutation =
DgraphProto.Mutation.newBuilder()
.setSetNquads(ByteString.copyFromUtf8(triples))
.build();
DgraphProto.Request request=DgraphProto.Request.newBuilder()
.addMutations(mu)
setCommitNow(true)
.build();
response=txn.doRequest(request);
so when i check for the uid’s for the same username it creates two seperate nodes or uid what am i missing
Note:Underscores in triples are in place just some editing issue while placing here
amanmangal
(Aman Mangal)
September 25, 2019, 10:27am
2
Could you print the triples
variable and paste the results here?
for user1 and category1
_:user1 <name> "user1" .
_:user1 <dgraph.type> "user" .
_:category1 <cname> "category1" .
_:category1 <dgraph.type> "category" .
_:category1 <userId> "user1" .
_:user1 <category> _:category1 .
for user1 and category2
_:user1 <name> "user1" .
_:user1 <dgraph.type> "user" .
_:category2 <cname> "category2" .
_:category2 <dgraph.type> "category" .
_:category2 <userId> "user1" .
_:user1 <category> _:category2 .
amanmangal
(Aman Mangal)
September 25, 2019, 10:36am
4
And what’s your query that you are running?
user=“user1”
String query = " query all($a: string){\n "+"all(func: eq(name, $a)) {\n "+"name\n "+"category {\n "+“cname\n “+”}\n “+”}\n “+”}”;
Map<String, String> vars = Collections.singletonMap("$a", user);
DgraphProto.Response res = dgraphClient.newTransaction().queryWithVars(query,vars);
this for getting the details of a user from the name
amanmangal
(Aman Mangal)
September 25, 2019, 11:25am
6
Based on the data, I can see that you have inserted both the users with same name
user1
which is why the query is returning two different nodes.
I have the case where each user can have multiple categories
so i want a user node for user1 that has edges to multiple nodes to categories say category1 and category2 so how do i manage that if i specify a different user ??
User1 ->Category1,Category2
User2->Category1
can you help me for the above scenario
Hi,
The above query is resolved but had another query
if i have following structure
user → categories->billers
so if i know the uid of user how can a reach to the node of a particular category with a name using that uid
String query = “query {\n” +
“user as var(func: eq(name, “+userName+”))\n” +
“category as var (fun: eq(cname,”+categoryName+")" +
“{” +
"name @filter (uid_in(name, uid(user))) " +
“}”+
“}\n”;
some help on above query ??
Schema
type user{
name:string
category:[category]
}
type category
{
cname:string
userId:String
biller:[biller]
}
type biller
{
bname:string
}