Insert vertex into local Cosmos DB Emulator using Gremlin Console

1

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?

console
azure-cosmosdb
gremlin
azure-cosmosdb-gremlinapi
asked on Stack Overflow Sep 18, 2019 by jkost4

4 Answers

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).

answered on Stack Overflow Sep 19, 2019 by Daniel Kuppitz
1

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

answered on Stack Overflow Sep 20, 2019 by jkost4
1

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.

answered on Stack Overflow Oct 28, 2019 by SebastianG
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.

answered on Stack Overflow Dec 10, 2019 by Sandman

User contributions licensed under CC BY-SA 3.0