azure-docs icon indicating copy to clipboard operation
azure-docs copied to clipboard

Code sample not working in Azure CosmosDB with Gremlin

Open kedzilla opened this issue 2 years ago • 1 comments

Code does not work in Azure CosmosDB, partition key is always needed when creating vertices.

g.addV('person').
  property('id', 'thomas.1').
  property('firstName', 'Thomas').
  property('lastName', 'Andersen').
  property('age', 44)

as stated in the documentation does not run successfully.

Error message from Azure:

Failure in submitting query: g.addV('person'). property('id', 'thomas.1'). property('firstName', 'Thomas'). property('lastName', 'Andersen'). property('age', 44): Script eval error: ActivityId : 11d3e271-6f6b-4999-ab30-0f1d5a1be41b ExceptionType : GraphRuntimeException ExceptionMessage : Gremlin Query Execution Error: Cannot add a vertex where the partition key property has value 'null'. GremlinRequestId : e4f842f2-c18c-4dc5-bcf4-34f436e20bf7 Context : graphcompute Scope : graphcomp-execquery GraphInterOpStatusCode : GraphRuntimeError HResult : 0x80131500


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

kedzilla avatar Dec 13 '22 20:12 kedzilla

@kedzilla Thanks for your findings, I'm assigning this to the author for the feedback review.

GeethaThatipatri-MSFT avatar Dec 14 '22 00:12 GeethaThatipatri-MSFT

@kedzilla, after reading through this article, I'm not sure if it recommends a partition key for this code sample.

I created a graph and used /lastName as the partition key and things worked fine.

What partition key did you use?

seesharprun avatar Jan 10 '23 16:01 seesharprun

@kedzilla, we will update the article to indicate that you can use lastName as a partition key if you're following along with the samples.

seesharprun avatar Jan 10 '23 16:01 seesharprun

Essentially, in each vertex you add to the graph, you need a property that has the graph's partition key.

Example:

  1. Create a Graph with a partition key /location, then

  2. Create a vertex with property "location": g.addV("users").property("location", "united kingdom").property("name", "jackson").property("age", "30")

CodeLexis avatar Jun 15 '24 09:06 CodeLexis