我试图在分区的CosmosDB图中的顶点上设置属性。如果顶点之前有任何属性,我希望它们被擦除并替换为新的属性集。
即使删除也有点棘手,因为“分区键”作为不可删除的属性公开。
g.V('nodeId').has('partitionKey','xx').properties().drop()
- >“Gremlin查询执行错误:无法删除分区属性。”
幸运的是,分区键属性的id
是可预测的,可用于过滤它:
g.V('nodeId').has('partitionKey','xx')
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()
现在我不得不尝试添加新属性。我试过了:
g.V('nodeId').has('partitionKey','xx')
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()
.property('a','valA')
.property('b','valB')
但是看起来我正在将property()
步骤应用于(空)属性列表,而不是顶点。错误不是很有帮助:
Gremlin Query Compilation Error: Column reference R_200324["_value"] cannot be located in the raw records in the current execution pipeline.
我尝试将property()
步骤应用于顶点(通过select
-ing),但我必须做错事:
g.V('nodeId').has('partitionKey','xx')
.as('v')
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()
.select('v')
.property('a','valA')
.property('b','valB')
这给出了与上面相同的错误。
我也试过.back('v')
而不是.select('v')
,但看起来像cosmosDB不支持back
。
有什么建议?
我认为你遇到的问题与this S.O. answer中描述的相同。
基本上,.drop()
会从遍历中过滤掉所有内容,并阻止以下任何代码执行任何操作。
你可以像这样使用.sideEffect()
来解决这个问题
g.V('nodeId').has('partitionKey','xx')
.sideEffect(properties().not(has('id', 'nodeId|partitionKey')).drop())
.property('a','valA')
.property('b','valB')