Reputation: 205
i have a node.js app where i have to create a unique user based on the username property of a node such as
(:USER {name:'username',password:'pass123'})
so i want to run a query that checks if a user with the given username exists or not and if not then create the node and set its password.
I am thinking about which way to go.. either create a CONSTRAINT or use CREATE UNIQUE ON MATCH ON CREATE or first run a MATCH query and if it returns data then run CREATE query based on the result
i am using the neo4j-driver for node and the query run returns the result Obj
Upvotes: 1
Views: 393
Reputation: 30407
Sounds like name
on :USER is meant to be unique in your model, so creating a unique constraint on this is the way to go.
As for the creation of the node itself, using MERGE along with its ON CREATE clause should do the trick.
Upvotes: 0