I have a problem running this Gremlin query in Azure CosmosDB.
g.V().
has('node', 'id', 'new').
fold().coalesce(
unfold(),
addV('node').
property('id', 'new').
property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
).V().
has('node', 'id', 'new').
as('new').
V().
has('node', 'id', 'root').
coalesce(
outE('contains').where(inV().as('new')),
addE('contains').to('new')
).V().
has('node', 'id', 'new').
as('new').
V().has('userGroup', 'id', 'userGroup1').
coalesce(
outE('hasAccess').where(inV().as('new')),
addE('hasAccess').to('new')
)
I get two problems:
- If I have many other nodes in the DB (350000) the query times out. I have not been able to test this in TinkerPop.
- The hasAccess edge is not created. This works in TinkerPop.
The base for the query is (images from gremlify.com):

g.addV('node').
property('id', 'root').
property('partitionKey', '33cb2571f8e348eaa875e6a2639af385')
g.addV('userGroup').
property('id', 'userGroup1').
property('partitionKey', '1')
and I want to end up like:

with a query that can be run multiple times without changing anything (idempotent). If I do this in separate queries it works fine:
g.V().
has('node', 'id', 'new').
fold().coalesce(
unfold(),
addV('node').
property('id', 'new').
property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
)
g.V().
has('node', 'id', 'new').
as('new').
V().
has('node', 'id', 'root').
coalesce(
outE('contains').where(inV().as('new')),
addE('contains').to('new')
)
g.V().
has('node', 'id', 'new').
as('new').
V().has('userGroup', 'id', 'userGroup1').
coalesce(
outE('hasAccess').where(inV().as('new')),
addE('hasAccess').to('new')
)
But I want to save two calls to the DB and do it in one go.