Posted by lxwithgod:
v0.9.2
dgraphclient.newTransaction().query,this function can’t insert/delete data,
please tell me,how do i insert edge’data?
Posted by lxwithgod:
v0.9.2
dgraphclient.newTransaction().query,this function can’t insert/delete data,
please tell me,how do i insert edge’data?
raitraidma commented :
To insert/delete, you must use mutate().
Insert using JSON:
DgraphClient.Transaction transaction = getDgraphClient().newTransaction();
DgraphProto.Mutation mutation = DgraphProto.Mutation.newBuilder()
.setSetJson(ByteString.copyFromUtf8("[" +
"{\"uid\":\"0x123\", \"name\":\"Tom\"}," +
"{\"name\":\"Jane\"}]"))
.build();
transaction.mutate(mutation);
transaction.commit();
However, I’m also curious how to insert data using DgraphProto.NQuad
and how to use blank nodes with dgraph4j.
lxwithgod commented :
can you insert edge relationship?
DgraphClient.Transaction transaction = getDgraphClient().newTransaction();
DgraphProto.Mutation mutation = DgraphProto.Mutation.newBuilder()
.setSetJson(ByteString.copyFromUtf8(
“{“uid”:“0x123”, “call”:“0x124”}”))
.build();
transaction.mutate(mutation);
transaction.commit();
lxwithgod commented :
i meet a except:
io.dgraph.DgraphException: Input for predicate call of type uid is scalar
raitraidma commented :
They have added new tests that are helpful: https://github.com/dgraph-io/dgraph4j/blob/master/src/test/java/io/dgraph
deepakjois commented :
We have added some code in the tests folder which should illustrate the different scenarios. Hopefully they can guide you along in writing your own code to perform insertions.