Search code examples
javascriptnode.jsgremlinamazon-neptune

Gremlin query: how to specify sort order in javascript


I am using AWS Neptune.

I want to perform a simple gremlin query that returns vertices sorted in decreasing order by a property named "timestamp".

I can do this using the gremlin console:

gremlin> g.V().has('timestamp').order().by('timestamp', desc).fold()

But when I use this same statement from my nodejs application, I get the error "ReferenceError: desc is not defined". I am not surprised by the error, since I have not defined "desc".

My question: how do I pass the sort order in the gremlin query?

Am I missing an import?

I tried passing in the string 'desc' -- that didn't work.


Solution

  • I think you're just missing an import - in 3.3.3:

    const gremlin = require('gremlin');
    const order = gremlin.process.order;
    

    You can read more about it here. Note that 3.3.4 which is not yet released officially will have support for desc and asc as opposed to decr and incr.