How do I assign an id to the edge of the CosmosDB graph when I created it?

I see in the docs that mentions that UserSuppliedIds is supported for edges, but any edge I create ignores my .property assignment to id and assigns a guid. I don't want to add duplicate edges between two vertices, so I was going to give it my own id (and then I can quickly and efficiently execute the query using normal sql syntax). How can I use my own "id" for the edge?

+3


source to share


3 answers


What documents are you linking to? Are these the Gremlin documents?

Note that we are currently managing the IDs of the edges ourselves so that the edges can be placed with the original vertices for query efficiency reasons. And this is a bug in which we don't throw an exception when an edge is actually set.

We are changing this behavior to allow users to specify an id when creating an edge. I'll check with the team and give you the ETA for that.



Thanks again for reporting this. Please let us know if we can help in any other way.

Jayanta

+1


source


I tested the following gremlin expression which adds an edge and assigns a custom one id

.

g.V('1231234').addE('postedTo').property('id', '1231234:post_4').from(g.V('post_4'))

      

This worked using the latest and previous versions of the Microsoft.Azure.Graph nuget package ( 0.2.4-preview and 0.2.2-preview ):



Note. The Edge or vertex property id

can only be assigned when an element is created using the addV

or operations addE

. After the item is written, the property id

is read-only.

I haven't had time to test this on a graph server instance, however the 0.2.2-preview

package version should be comparable to what is being deployed, so I expect the same results.

+1


source


Since it doesn't seem to be supported via the Gremlin API today, I would suggest you take a look at using the Document for CRUD APIs for your graphic elements. This is the approach that I took at work, and we dealt with it successfully. Basically, if you insert multiple edges and edges through Gremlin and then validate the resulting documents using SQL in the portal, you should be able to see the format expected in the underlying store.

Based on this, we have developed several libraries that use POCO for different types of vertices and boundaries and translate them into the graph format expected in the Cosmos backend. This will give you complete control over the choice of IDs for your edges. A very important and common use case that you mentioned, which is also important for our system, is the ability to prevent more than one edge for a particular vertex by limiting it to an ID.

0


source







All Articles