manesioz
manesioz

Reputation: 837

How to set a list attribute to a node?

This seems like a simple use case but I'm having trouble locating an example in the docs.

I want to do the following:

MERGE(node:Graph{id:{id}})
    ON CREATE SET node.firstseen = timestamp(),
    SET node.id = {id}, 
    node.list = [list] 

Examples of this would be appreciated, thanks!

Upvotes: 1

Views: 161

Answers (2)

František Hartman
František Hartman

Reputation: 15086

You have a comma before your SET clause:

    ON CREATE SET node.firstseen = timestamp(),
                                              ^

The correct query is

MERGE (node:Graph {id:$id})
ON CREATE SET node.firstseen = timestamp()
SET
node.list = $list

You don't need to set the id field, the MERGE takes care of this. The list field will be set every time you call the query, the firstseen timestamp only when the node doesn't exist.

Upvotes: 1

cybersam
cybersam

Reputation: 67009

Assuming you pass id and list as parameters:

MERGE (node:Graph {id: $id})
ON CREATE SET
  node.firstseen = timestamp(),
  node.list = $list

You cannot have a SET clause within another SET clause. Besides, it is unnecessary to SET node.id = $id anyway, since your MERGE already guarantees that property has that value.

Upvotes: 1

Related Questions