# Edge data format?

**URL:** <https://discuss.dgraph.io/t/edge-data-format/9671>\
**Category:** Dgraph\
**Tags:** dataset, dgraph\
**Created:** [August 25, 2020, 9:28pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671 "2020-08-25T21:28:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 9:28pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/1 "2020-08-25T21:28:21Z")

</div>

Hi everyone.

I have a question about my data set. I thought I had everything figured out:

```auto
Types : 
Person 
  firstName
  lastName
  gender

Comment
  commentDate 
  length
  location

```

I have an edge file that looks like this:

```auto
{
  "set": [
    {
      "Personid": 32985348833579,
      "likesComment": {
        "Commentid": 2061584302097,
        "likesComment|likeDate": "2012-09-07T16:44:37.850+0000"
      }
    },
...

```

I’m trying to query all the people who have this edge “likesComment”, but no luck:

```auto
{
  q(func: type(Person))) {
    likesComment {
	Commentid
    }
  }
}

```

Is my data format set up incorrectly or am I querying incorrectly?

Thanks,  
Kevin

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 9:43pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/2 "2020-08-25T21:43:33Z")

</div>

Does your mutation/dataset has the `dgraph.type`?

e.g

```auto
{
  "set": [
    {
      "Personid": 32985348833579,
      "dgraph.type": "Person",
      "likesComment": {
        "Commentid": 2061584302097,
        "likesComment|likeDate": "2012-09-07T16:44:37.850+0000",
        "dgraph.type": "Comment"
      }
    },
...

```

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 9:50pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/3 "2020-08-25T21:50:40Z")

</div>

Hi Michel,

I loaded the types separate from the predicates. The Person file has the dgraph.type, and the Comment file also has dgraph.type.

Is the dgraph.type also necessary for the edge/predicate file?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 10:02pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/4 "2020-08-25T22:02:13Z")

</div>

> [@wood](#):
>
> Is the dgraph.type also necessary for the edge/predicate file?

No, just the entities.

humm, feels like something is missing somewhere.

> [@wood](#):
>
> ```auto
> Types : 
> Person 
> firstName
> lastName
> gender
> 
> Comment
> commentDate 
> length
> location
> 
> ```

I’m not sure if I got what you mean by this pseudo-schema. Can you make sure to make it with the syntax?

e.g. (confirm this - are all those preds on your schema?)

```auto
type Person {
  Personid
  firstName
  lastName
  gender
  likesComment
}

type Comment {
  Commentid
  commentDate 
  length
  location
}

```

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 10:12pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/5 "2020-08-25T22:12:24Z")

</div>

Here is a snippet from my Person file:

```auto
{
  "set": [
    {
      "Personid": 933,
      "firstName": "Mahinda",
      "lastName": "Perera",
      "gender": "male",
      "birthday": "1989-12-03",
      "creationDate": "2010-02-14T15:32:10.447",
      "locationIP": "119.235.7.103",
      "browserUsed": "Firefox",
      "language": "en",
      "email": "Mahinda933@boarderzone.com;Mahinda933@hotmail.com;Mahinda933@yahoo.com;Mahinda933@zoho.com",
      "dgraph.type": "Person"
    },
...

```

My personLikesComment file looks like this:

```auto
{
  "set": [
    {
      "Personid": 32985348833579,
      "likesComment": {
        "Commentid": 2061584302097,
        "likesComment|likeDate": "2012-09-07T16:44:37.850+0000"
      }
    },
...

```

So are you’re saying I need to include the predicate “likesComment” as a Person field? Many of my predicates are created upon mutation, because they are not part of the data within the Type files, but part of the edges instead.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 10:15pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/6 "2020-08-25T22:15:15Z")

</div>

> [@wood](#):
>
> So are you’re saying I need to include the predicate “likesComment” as a Person field?

Yes, the edges that connects nodes must go in the schema.

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 10:34pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/7 "2020-08-25T22:34:02Z")

</div>

If i include it as a field on the type, will I need to include it when I’m loading the Person types?

Something like this :

```auto
type Person {
  Personid
  firstName
  lastName
  gender
  likesComment {
    commentid
  }
}

```

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 10:36pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/8 "2020-08-25T22:36:04Z")

</div>

No, Dgraph’s type system doesn’t have nested. See what I have shared, it has to be like that.

> [@MichelDiz](#):
>
> ```auto
> type Person {
> Personid
> firstName
> lastName
> gender
> likesComment
> }
> 
> type Comment {
> Commentid
> commentDate 
> length
> location
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 10:37pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/9 "2020-08-25T22:37:08Z")

</div>

Ok, got it.

So if I include all the predicates onto the the types, I’ll need to reload and it should all be connected right?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 10:40pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/10 "2020-08-25T22:40:00Z")

</div>

What defines what is connected is the edge. If you have already created the edge, so now you need to set it on the Type definition on the schema (actually all should be already done on your Graph Modeling).

But, I’m not sure if that is the case. Something feels odd here. It should work even without the schema. Cuz the edge exists and you have set a minimum Type Definition. Not sure, try out what I said and let me know.

What I would see as an issue is by using expand(all) and other funcs.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 10:46pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/11 "2020-08-25T22:46:05Z")

</div>

Wait a minute, let’s recap.

So, you already have the users. Right? and this mutation

> [@wood](#):
>
> ```auto
> {
> "set": [
> {
> "Personid": 32985348833579,
> "likesComment": {
> "Commentid": 2061584302097,
> "likesComment|likeDate": "2012-09-07T16:44:37.850+0000"
> }
> },
> ...
> 
> ```

Would be your kind of “create the relation” right?

If that so, that’s wrong. Cuz you are not using a real UID or using an Upsert Block. This separation will create new nodes and not relations. You are creating 2 new nodes every time you run that mutation. And only those two will be connected by them selfs.

Let me know exactly what you are doing step by step.

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 11:02pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/12 "2020-08-25T23:02:27Z")

</div>

So I would need to create the relation by using the UID? Is there a way i could directly use the personid as the uid to avoid this complication?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 11:04pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/13 "2020-08-25T23:04:20Z")

</div>

> [@wood](#):
>
> So I would need to create the relation by using the UID?

Yes, see this if you wanna understand the basic CRUD op [https://www.youtube.com/watch?v=vhatoyZ2vic&t=2s](https://www.youtube.com/watch?v=vhatoyZ2vic&t=2s)

> [@wood](#):
>
> Is there a way i could directly use the personid as the uid to avoid this complication?

Yes, using upsert block [https://dgraph.io/docs/mutations/upsert-block/](https://dgraph.io/docs/mutations/upsert-block/)

@wood, BTW, why have you created this question at `Users/GraphQL`? It should be at `Users/Dgraph` (moved)

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 11:18pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/14 "2020-08-25T23:18:59Z")

</div>

Is there a way to do the upserting with live loader? The examples seem to handle it one case at a time…  
Would reformatting my data a certain way enable me to automate the loading process any further?

I thought there was an issue with my query… would it be better to put no topic?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 11:22pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/15 "2020-08-25T23:22:19Z")

</div>

> [@wood](#):
>
> Is there a way to do the upserting with live loader?

No as far I can tell. There is this PR [feat(live): added upsert in live loader by harshil-goel · Pull Request #6057 · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/pull/6057) which I don’t get a chance to understand how it works. It is on master only.

> [@wood](#):
>
> Would reformatting my data a certain way enable me to automate the loading process any further?

Nope, Dgraph works like this. Only Upserts can help you.

> [@wood](#):
>
> I thought there was an issue with my query… would it be better to put no topic?

Didn’t got your question. What do you mean?

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 11:24pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/16 "2020-08-25T23:24:41Z")

</div>

> [@MichelDiz](#):
>
> Didn’t got your question. What do you mean?

Creating the question under the Users/GraphQL topic. I wasn’t sure the exact topic to create it as, sorry ☹

> [@MichelDiz](#):
>
> > [@wood](#):
> >
> > Would reformatting my data a certain way enable me to automate the loading process any further?
> 
> Nope, Dgraph works like this. Only Upserts can help you.

I’m afraid the know the answer to this… are you saying I have to manually insert all the edges?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 11:31pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/17 "2020-08-25T23:31:20Z")

</div>

> [@wood](#):
>
> Creating the question under the Users/GraphQL topic.

Okay, that’s fine. When a user chooses such topic I assume that he is familiar with it. But by reading your issue I notice that it isn’t related to GraphQL. So, all questions of any kind should go first to `Users/Dgraph`. And then we can move it (the staff) if needed.

But no problem at all.

> [@wood](#):
>
> are you saying I have to manually insert all the edges?

You can use upsert for this. See, custom IDs aren’t handled by Dgraph. So Dgraph can’t be aware of its nature, patterns, standards, and so on. But you can still use your custom IDs, now you just need to learn how to use Upsert Block on daily basis.

---

<div class="post-metadata">

**Author:** ![wood](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wood](https://discuss.dgraph.io/u/wood)\
**Post date:** [August 25, 2020, 11:37pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/18 "2020-08-25T23:37:44Z")

</div>

> [@MichelDiz](#):
>
> Okay, that’s fine. When a user chooses such topic I assume that he is familiar with it. But by reading your issue I notice that it isn’t related to GraphQL. So, all questions of any kind should go first to `Users/Dgraph` . And then we can move it (the staff) if needed.

Got it, i’ll put new questions in the Dgraph topic.

> [@MichelDiz](#):
>
> You can use upsert for this. See, custom IDs aren’t handled by Dgraph. So Dgraph can’t be aware of its nature, patterns, standards, and so on. But you can still use your custom IDs, now you just need to learn how to use Upsert Block on daily basis.

I see, so there’s essentially no point of having UID for each Personid because DGraph will create its own UID upon loading. And in order to create a link from one Person object to another type, I would need to know the exact UID within the system to avoid creating a duplicate Person - am I getting this correctly?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 11:38pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/19 "2020-08-25T23:38:46Z")

</div>

One question, does your child data knows about the parent? I mean, to be able to link them without going one by one. One of the nodes needs to be aware of the other, so we can get that information and upsert right away. If not so, not even with dark magic would be possible.

See this query:

```auto
upsert {
  query {
    q(func: eq(Personid, "32985348833579")) {
      v as uid
    }
    q2(func: eq(Commentid, "2061584302097")) {
      v2 as uid
    }
  }

  mutation {
    set {
      uid(v) <likesComment> uid(v2) (likeDate="2012-09-07T16:44:37.850+0000") .
    }
  }
}

```

That would be a simple example. But to do an upsert that connects every node. Some of them have to be the source of truth of the context. If your data comes from other DB, maybe they export that info. Need to evaluate.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [August 25, 2020, 11:42pm UTC](https://discuss.dgraph.io/t/edge-data-format/9671/20 "2020-08-25T23:42:18Z")

</div>

> [@wood](#):
>
> so there’s essentially no point of having UID for each Personid because DGraph will create its own UID upon loading.

I think you mean having “custom” ID system right? Yeah, in that case it’s up to you to deal with other IDs systems. I see that other users use third party IDs, cuz they combine Dgraph with other DBs. So, in their case makes sense they do that work.

> [@wood](#):
>
> I would need to know the exact UID within the system to avoid creating a duplicate Person

Precisely.

[Next page](https://discuss.dgraph.io/t/edge-data-format/9671.md?page=2)
