# Now,how do i insert edge'data?

**URL:** <https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716>\
**Category:** Dgraph Clients\
**Tags:** untagged, dgraph4j\
**Created:** [November 21, 2017, 8:14am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716 "2017-11-21T08:14:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 21, 2017, 8:14am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/1 "2017-11-21T08:14:56Z")

</div>

_Posted by_ [lxwithgod](https://github.com/lxwithgod):

v0.9.2  
dgraphclient.newTransaction().query,this function can’t insert/delete data,  
please tell me,how do i insert edge’data?

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 21, 2017, 8:35am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/2 "2017-11-21T08:35:49Z")

</div>

[raitraidma](https://github.com/raitraidma) _commented_ :

To insert/delete, you must use mutate().

Insert using JSON:

```auto
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](https://docs.dgraph.io/query-language/#blank-nodes-and-uid) with dgraph4j.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 21, 2017, 9:02am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/3 "2017-11-21T09:02:14Z")

</div>

[lxwithgod](https://github.com/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();

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 21, 2017, 9:03am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/4 "2017-11-21T09:03:56Z")

</div>

[lxwithgod](https://github.com/lxwithgod) _commented_ :

i meet a except:  
io.dgraph.DgraphException: Input for predicate call of type uid is scalar

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 21, 2017, 12:22pm UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/5 "2017-11-21T12:22:06Z")

</div>

[raitraidma](https://github.com/raitraidma) _commented_ :

They have added new tests that are helpful: [https://github.com/dgraph-io/dgraph4j/blob/master/src/test/java/io/dgraph](https://github.com/dgraph-io/dgraph4j/blob/master/src/test/java/io/dgraph)

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [November 27, 2017, 5:13am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/6 "2017-11-27T05:13:15Z")

</div>

[deepakjois](https://github.com/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.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 11, 2020, 1:37am UTC](https://discuss.dgraph.io/t/now-how-do-i-insert-edgedata/7716/7 "2020-07-11T01:37:17Z")

</div>

Closed on July 11, 2020, 1:37am UTC


