Search code examples
gremlinazure-cosmosdb-gremlinapi

Gremlin hasId using property of parent


I would like to filter out by an id. The value of the id is on a property of the parent. Example:

g.V('1234')
    .as('parent')
    .out()
        .has(id, parent.childId). <--- how do I get the parent id?

How would one approach this?

The closest I've been able to get is the following query, but it seems to ignore the has and simply returns all results of out.

g.V('123')
    .as('parent')
        .values('childId')
        .as('childIdValue')
    .select('parent')
        .out('hasChild')
        .has('id', select('childIdValue'))

EDIT

It works as expected when a vertex property other than the Id is used. Example:

g.V('123')
    .as('parent')
        .values('childId')
        .as('childIdValue')
    .select('parent')
        .out('hasChild')
        .has('childProp', select('childIdValue'))

I've tried all variations of id that I can think of. 'id', id, id().


Solution

  • You can compare an ID using a where by approach. For example something like:

    where(eq('parent')).by('childProp').by('childId')