neo4j - Cant use Merge inside foreach for existed nodes -
i expecting following query create nodes (only if exits) , relations given source node (1) , list(2) way:
merge (p1:c9{userid: '1'}) p1, [{userid:"2"}] users foreach (user in users | merge ((p1)-[r1:follow]->(:c9 {userid: user.userid})))
thats outcome:
now if executing query again switching node id's way:
merge (p1:c9{userid: '2'}) p1, [{userid:"1"}] users foreach (user in users | merge ((p1)-[r1:follow]->(:c9 {userid: user.userid})))
we got this:
neo4j duplicated me node id=1. want merge in case of existed nodes.
i expected see 2 nodes connected each other merging existed nodes.
any idea should fix?
thanks, ray.
i avoid foreach
when can use unwind
, start this:
merge (p1:c9 {userid: '1'}) p1, [{userid:"2"}] users unwind users user merge (p1)-[r1:follow]->(:c9 {userid: user.userid})
sometimes want separate node creation relationship creation. if both @ same time, think neo4j can think want unique combination of node (with properties) , relationship.
merge (p1:c9 {userid: '1'}) p1, [{userid:"2"}] users unwind users user merge (p2:c9 {userid: user.userid}) merge (p1)-[r1:follow]->(p2)
Comments
Post a Comment