BobCitron
BobCitron

Reputation: 35

Using ArangoDB EDGES function, can't get the right vertex with includeVertices options

Using ArangoDB to describe a friend relationship, I want to know the friends of a specific user A. Because it's a test sample, I know that A is friend with B.

I have users in a document collection and an edge collection containing the information from "_from" being friend to "_to". If A is friend to B, B must be friend to A. i.e.: if there's an edge _from A _to B, an other edge _from B _to A does exist.

I use the function EDGES on my friend collection, to know which is friend to the user "u4", which _id is 2465087832. He must be friend with "u1", which _id is 2462335320. Because I want to have more than just the document ID, I set the option "includeVertices" to true.

Here are my request.

LET out = EDGES(friends, "db/2465087832", "outbound", null, {includeVertices: true})

And the answer:

[
    {
      "edge": {
        "_id": "db/2468102488",
        "_from": "db/2465087832",
        "_to": "db/2462335320",
        "_rev": "2468102488",
        "_key": "2468102488"
      },
      "vertex": {
        "_id": "db/2465087832",
        "_key": "2465087832",
        "_rev": "3962323288",
        "id": "u4"
      }
    }
  ]

As a result, I have the good edge (u4 is friend to u1), but the vertex included is the one from the requested user (id: u4). I tried using "inbound" as a direction, instead of "outbound".

LET out = EDGES(friends, "db/2465087832", "inbound", null, {includeVertices: true})

And the result is:

 [
    {
      "edge": {
        "_id": "db/2468364632",
        "_from": "db/2462335320",
        "_to": "db/2465087832",
        "_rev": "2468364632",
        "_key": "2468364632"
      },
      "vertex": {
        "_id": "db/2465087832",
        "_key": "2465087832",
        "_rev": "3962323288",
        "id": "u4"
      }
    }
  ]

As you can see, still "u4" as vertex, even is the edge is the good one (u1 is friend to u4).

At last, I tried to use "any" as a direction.

LET any = EDGES(friends, "db/2465087832", "any", null, {includeVertices: true})

And the surprising answer:

[
    {
      "edge": {
        "_id": "friends/2468364632",
        "_from": "user/2462335320",
        "_to": "user/2465087832",
        "_rev": "2468364632",
        "_key": "2468364632"
      },
      "vertex": {
        "_id": "user/2462335320",
        "_rev": "3956687192",
        "_key": "2462335320",
        "id": "u1"
      }
    },
    {
      "edge": {
        "_id": "friends/2468102488",
        "_from": "user/2465087832",
        "_to": "user/2462335320",
        "_rev": "2468102488",
        "_key": "2468102488"
      },
      "vertex": {
        "_id": "user/2462335320",
        "_rev": "3956687192",
        "_key": "2462335320",
        "id": "u1"
      }
    }
  ]

Here the answer contains both edge (A to B and B to A) which is correct, but for both the vertex is the one from u1. This three results seem to be inconsistent: for "inbound"/"outbound" : the vertex was u4, and for "any" the vertex is "u1". Is there a bug in my code? An option that I should use?

Thanks,

BobCitron

Upvotes: 3

Views: 204

Answers (1)

mchacki
mchacki

Reputation: 3267

thank you very much for spotting this, it is actually a bug in our core not in your code

I did just fix it and it will be included in the next 2.6. bugfix release and in 2.7(devel). The expected behaviour is as you describe.

Do you actually need the information stored in the Edges? If not you could consider using the NEIGHBORS function in this case, which is more performant.

Upvotes: 1

Related Questions