Setting a temporal type property using a map


(Wheresrhys) #1

I can use

SET node.timestamp = datetime($properties.timestamp)

To set a temporal type on a node

But, in general, I am setting lots of properties on the node. Before temporal types came along I was able to do:

SET node += $properties

or

CREATE (node:Type $properties)

How can I modify the $properties object in advance in order to set some temporal types and maintain the same (or very similar) cypher queries. Using the javascript bolt client


(M. David Allen) #2

A datetime is a special cypher type. The Neo4j JS driver allows you to create instances of those here:

Have you tried creating instances like this and putting them in your maps and then sending those property maps to the server? What specific error do you get if you do?


(Wheresrhys) #3

I was looking into that, but if that behaviour is supported, it's not documented:

Even if it works, I'm reluctant to use an undocumented feature


(William Lyon) #4

If you don't want to use the driver types for this, you could modify the properties object in Cypher.

For example, if your properties param object looks like this:

{dateOfBirth: "2015-03-24", name: "Bob"}'

Then you could use the date (or datetime, etc) function to cast dateOfBirth to a date type:

WITH $properties AS properties
WITH properties {.*, dateOfBirth: date(properties.dateOfBirth)} AS properties
CREATE (p:Person) SET p=properties

(Wheresrhys) #5

Using the driver types actually works very nicely. I just wish it was documented that this behaviour is supported :confused:. Where should I raise that the documentation on parameters needs updating?


(William Lyon) #6

Ah gotcha. I've raised this internally to add to the docs.