The following query fails:
MATCH n:User
WHERE n.email = "test"
SET n = {data}, n.created = timestamp()
RETURN n
Is this expected? Is it a bug? Is there a workaround? Do I have to compute the timestamp and send it along with {data}?
A slight modification of your statement using 2 SET clauses works:
MATCH n:User
WHERE n.email = "test"
SET n = {data}
SET n.created = timestamp()
RETURN n
Related
How to set the cypher.lenient_create_relationship = true in neo4j.conf.
I tried to create Relationships using Cypher Query Language but it says no changes later I use OPTIONAL MATCH to forcefully connect the relationships but after I pass the OPTIONAL MATCH command it asked me to do this, how can I rectify this issue?
Here is my before and before code.
**Before
MATCH (a:Neuron), (b:Structur)
WHERE a.doi = "10.1126/science.aah511477" AND a.local_id = 1 AND b.acronym = "SSp-tr"
CREATE (a)-[r:BELONGS_TO]->(b)
after***
OPTIONAL MATCH (a:Neuron), (b:Structur)
WHERE a.doi = "10.1126/science.aah511477" AND a.local_id = 1 AND b.acronym = "SSp-tr"
CREATE (a)-[r:BELONGS_TO]->(b)
RETURN a, b, r
How do I create and update nodes and property using plain cypher query?
Below is my query:
MERGE (c:contact {guid : '500010'})
ON CREATE SET
c.data_source = '1',
c.guid = '500010',
c.created = timestamp()
ON MATCH SET
c.lastUpdated = timestamp()
MERGE (s:speciality {specialtygroup_desc : 'cold'})
ON CREATE SET s.data_source = '1',
s.specialtygroup_desc = 'fever',
s.created = timestamp()
ON MATCH SET s.data_source = '1',
s.specialtygroup_desc = 'comman cold',
s.lastUpdated = timestamp()
MERGE (c)-[r:is_specialised_in]->(s)
ON CREATE SET
r.duration = 1
ON MATCH SET
r.duration = r.duration + 1
On the first run, node is created as "fever".
On the second run, I have updated the specialty_group to "common cold". But it is creating new node with "fever". I am not able to update the "fever" to "common cold".
What changes should I make to the above query?
The MERGE (s:speciality {specialtygroup_desc : 'cold'}) clause looks for a specialtygroup_desc value of "cold".
During the first execution, that MERGE clause finds no "cold" node -- so it creates one, and the subsequent ON CREATE clause changes it to "fever".
During the second execution, that MERGE again finds no "cold" node (since it is now a "fever" node), so it again creates a "cold" node and the ON CREATE clause yet again changes it to "fever". The ON MATCH clause is never used. This is why you end up with another "fever" node.
Unfortunately, you have not explained your use case in enough detail to offer a recommendation for how to fix your code.
I think you want to update all node "cold" to "common cold" and if not exists "cold" or "common cold", create new "fever" ?
My suggestion:
OPTIONAL MATCH (ss:speciality {specialtygroup_desc : 'cold'}
SET ss.specialtygroup_desc='common cold', ss.lastUpdated = timestamp()
MERGE (c:contact {guid : '500010'})
ON CREATE SET
c.data_source = '1',
c.guid = '500010',
c.created = timestamp()
ON MATCH SET
c.lastUpdated = timestamp()
MERGE (s:speciality {specialtygroup_desc : 'common cold'})
ON CREATE SET s.data_source = '1',
s.specialtygroup_desc = 'fever',
s.created = timestamp()
MERGE (c)-[r:is_specialised_in]->(s)
ON CREATE SET
r.duration = 1
ON MATCH SET
r.duration = r.duration + 1
How to do somethink like that:
data = {'field1': 'data1', 'field2': '#data2', 'field3': 'data3', 'field4': 'data4'}
r = session.run("MATCH (n) WHERE id(n) = 287 SET n = {props}", parameters=data)
You should also use a parameter for id
Otherwise using a dictionary for parameters works, not sure about kwargs
data = {'field1': 'data1', 'field2': '#data2', 'field3': 'data3', 'field4': 'data4'}
r = session.run("MATCH (n) WHERE id(n) = {id} SET n += {props}",
{'id':287, 'props':data})
My graph contains a set of nodes which are enumerated using a dedicated field fid. I want to update this enumeration periodically.
My current approach is to reset the enumeration and execute multiple statements that increase the fid for each node.
1. (f:File) set f.fid = -1
for(int i = 0; i < count ; i++) {
2. (f:File) set f.fid = i where id(f) = nodeId
}
I guess it should be possible to execute this task using a single cypher statement using the foreach clause.
MATCH p=(f:File)
FOREACH (n IN nodes(p)| SET f.fid = -1 )
I was looking for something similar to this statement.
MATCH (f:File)
WITH COLLECT(f) AS fs
WITH fs, i = 0
FOREACH (f in fs, i=i+1| SET f.fid = i ) return f.fid, f.name
Based on the following console set : http://console.neo4j.org/r/447qni
The following query seems to do the trick :
MATCH (f:File)
WITH collect(f) as f, count(f) AS c
UNWIND range(0,c-1) AS x
WITH f[x] AS file,x
SET file.iteration = x+1
I have a set of nodes with a property, myproperty = "James" I want to update that property from (myproperty) to (name).
Is there any way to this with Cypher?
Solved by myself, heres what I did:
MATCH (n:term)
SET n.name = n.label
REMOVE n.label
RETURN n
You can change your old column name by using following query
MATCH (n:term)
SET n.name = n.myproperty
REMOVE n.myproperty
RETURN n
match (a:employee {employeeId:123,location:1})
set a.newProperty=a.oldProperty
remove a.oldProperty
return a;