3

I am trying to add vertices (and eventually edges) to a local Cosmos DB graph using the Gremlin console. I've been following this tutorial. However, whenever I try to add a vertex, I get an error about the partition key.

My query:

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

The error:

ActivityId : cd07f7be-d824-40fa-8137-0f2726a9c26d
ExceptionType : GraphRuntimeException
ExceptionMessage :
Gremlin Query Execution Error: Cannot add a vertex where the partition key property has value 'null'.
Source : Microsoft.Azure.Cosmos.Gremlin.Core
GremlinRequestId : cd07f7be-d824-40fa-8137-0f2726a9c26d
Context : graphcompute
Scope : graphcomp-execquery
GraphInterOpStatusCode : GraphRuntimeError
HResult : 0x80131500
Type ':help' or ':h' for help.
Display stack trace? [yN]

How can I fix my query and insert the data?

jkost4
  • 73
  • 1
  • 8

4 Answers4

3

Did the same mistake of mixing the two values up. So when you add your azure database, you have to specify a partition key, I picked '/client';

Now when I do my query, I have to add this property:

.property('client', 'pk')

-- the first value has to be the key itself, and the second one 'pk', short for 'partitionKey'; Then in your document you have to add a property:

client: 'TESTCLIENTID'

But again, a lot of this is about what your 'partitioning' strategy is based on, which is something you have to decide upfront for each collection, this video from Azure explains things in more detail quite good.

SebastianG
  • 8,563
  • 8
  • 47
  • 111
1

I don't have a CosmosDB test environment, but there's a public sample project:

Looks like you have to add a pk property (which most likely means "partition key", and should be configurable somehow).

Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
  • Thanks, I've tried this but it hasn't worked either. We are also able to insert vertices to our CosmosDB instance on Azure without partition keys, so we would like to be able to insert vertices into the local instance without a partition key as well. – jkost4 Sep 20 '19 at 15:17
  • Maybe this is not supported, in this case we would add partition keys to the Azure instance to maintain consistency. But we still do not know how to insert records using a partition key. – jkost4 Sep 20 '19 at 15:27
1

You don't need to add a partition key in your g.addV i looked at what the "Quick start" tab creates for you in the portal which is the "graphdb/mycollection" database/collection. You can create your own which works fine without specifying partition key when adding a vertex... Just specify Partition key

/_partitionKey

and check the checkbox

My partition key is larger than 100 bytes

That solved it for me anyway.

Sandman
  • 795
  • 7
  • 16
0

I had mixed up the partition key label and value. Reversing these fixed my issue.

jkost4
  • 73
  • 1
  • 8