0

Trying to update properties if it exists using gremlin query I am getting error as Cannot find name 'has' and the same query runs fine in Neptune notebook. But for the same thing in node.js I am getting error at "has"

Below is the query. What am I missing here? Graph.V(Id).hasLabel('test').optional(has('nameProperty').property(single,'nameProperty', 'value'))

Juan Medina
  • 565
  • 7
  • 15
userrj_vj_051620
  • 147
  • 2
  • 12

1 Answers1

0

When called from code "anonymous" traversals - parts of a query not connected to others by a dot, may need to be prefixed with __. as below:

Graph.V(Id).
   hasLabel('test').
   optional(__.has('nameProperty').
      property(single,'nameProperty', 'value'))

The __. is actually a special class that TinkerPop defines for cases such as this one. Note that in many languages like Java and Python it is possible to statically include/import this class so that you do not actually have to use the __. syntax unless you encounter a reserved word collision with the language such as not in Groovy.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • I have updated it like below still I am getting same error `const __ = gremlin.process.statics; Graph.V(Id). hasLabel('test').optional(__.has('nameProperty').property(single,'nameProperty', 'value'))` – userrj_vj_051620 Mar 08 '21 at 09:59
  • I did a test just now using the 3.4.10 Gremlin JavaScript client and Node.js and had no problems. I am not sure what may be happening in your environment. – Kelvin Lawrence Mar 08 '21 at 13:56
  • In case it helps these are the imports I used in my test: `const gremlin = require('gremlin'); const Graph = gremlin.structure.Graph; const __ = gremlin.process.statics; const { t,order,cardinality,column,scope,pop,operator,P,traversal } = gremlin.process; ` – Kelvin Lawrence Mar 08 '21 at 14:05