I'm using gremlin-javascript
to talk to AWS Neptune from Node. According to the docs and quickstart, dates should be set using datetime()
.
I did not find an implementation of this datetime()
function in gremlin
. Where should this be imported from?
g.addV("user").property(single, "createdDate", datetime(now().toISOString());
"ReferenceError: datetime is not defined"
So the 'datetime()' method that Neptune provides is intended to be used when sending queries to the graph as text Strings. Here is an example from the Gremlin console attached to a running Neptune instance:
gremlin> g.addV('test').property('timestamp',datetime('2018-11-04T00:00:00')).property(id,'t1')
==>v[t1]
gremlin> g.V('t1').valueMap()
==>{timestamp=[Sun Nov 04 00:00:00 UTC 2018]}
gremlin> g.V().has('timestamp',gt(datetime('2018-11-03T00:00:00')))
==>v[t1]
Now, if you are using a GLV language such as Gremlin Python you can use the native Python datetime
class instead. As shown below. Note while the two examples share the name datetime
they are completely different iin everything but name. I ran this from a Jupyter Notebook using Gremlin Python but it works equally well in the Python console or as a standalone Python app.
import datetime
g.addV('test').\
property(id,'x2').\
property('timestamp',datetime.datetime.now()).next()
v[x2]
g.V('x2').valueMap(True).next()
{<T.label: 3>: 'test',
<T.id: 1>: 'x2',
'timestamp': [datetime.datetime(2018, 11, 5, 15, 3, 52, 29000)]}
Please forgive a Python example - I know you are using Javascript. I just happened to have a Python environment configured but the same principles should apply.
All of this said as I and others have mentioned in other posts, I prefer to store timestamps using epoch time. Typically I use 10 or 13 digit integer representations of time depending upon the precision I need. This is also a fairly portable way to store time information and easy to test using greater than/less than predicates etc.
Anyway, I hope this helps clarify your choices a little bit. Cheers, Kelvin.
UPDATED October 15th 2019 Specifically in the Neptune case, using the native date object from Java, Python etc. may result in queries that run a little faster due to the way the Neptune Engine evaluates queries.