使用 Gremlin 控制台将顶点插入本地 Cosmos DB 模拟器

Insert vertex into local Cosmos DB Emulator using Gremlin Console

我正在尝试使用 Gremlin 控制台将顶点(最终是边)添加到本地 Cosmos DB 图形。我一直在关注 this tutorial。但是,每当我尝试添加顶点时,都会收到有关分区键的错误。

我的查询:

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

错误:

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]

如何修复我的查询并插入数据?

我没有 CosmosDB 测试环境,但有一个 public 示例项目:

看起来你必须 add 一个 pk 属性(这很可能意味着 "partition key",并且应该可以通过某种方式进行配置)。

我混淆了分区键标签和值。扭转这些解决了我的问题。

犯了同样的错误,将两个值混淆了。所以当你添加你的 Azure 数据库时,你必须指定一个分区键,我选择了'/client';

现在,当我进行查询时,我必须添加此 属性:

.property('client', 'pk')

--第一个值必须是键本身,第二个值'pk','partitionKey'的缩写;然后在你的文档中你必须添加一个 属性:

client: 'TESTCLIENTID'

但同样,其中很多是关于您的 'partitioning' 策略所基于的,这是您必须为每个系列预先决定的事情,this video from Azure explains things in more detail quite good.

您不需要在 g.addV 中添加分区键 我查看了 "Quick start" 选项卡在门户中为您创建的内容,即 "graphdb/mycollection" database/collection.您可以创建自己的工作正常而无需在添加顶点时指定分区键...只需指定 分区键

/_partitionKey

并选中复选框

My partition key is larger than 100 bytes

无论如何,这已经为我解决了。