java - Neo4j match... merge cypher syntax for UPSERT is returning (no rows) -
i started learning graphdb neo4j yesterday, now, want perform upsert operation shown below;
match (circle:circle {id:3, cycleid:5}) merge (member1:member {id:1}) -[invited:invited_to_join {c:circle, time:timestamp()}]-> (member2:member {id:2}) return member1, member2, invited, circle
according docs here http://neo4j.com/docs/stable/query-merge.html if node circle assigned properties not exist node , specified relationship should created, otherwise, update should performed on node , relationships. not happen. rsponse says (no rows)
. see below;
could please point me i'm not doing correctly?
edit: want create circle
, member1
, member2
, their relationships on fly without worrying whether nodes exist, if do, update them accordingly
edit: make myself clearer after comments , suggestions @davebennet @cybersam, & @michaelhunger
(main aim:) to create relationship implies member1
invited member2
join circle3
- if node(s)/relationship(s) not exist, create them
- if node(s)/relationship(s) exist update them
in cases, there should no duplicates of nodes or relationships
this shouldn't difficult it's turning out. i'm starting think there's documentation failing appropriately convey?
see here: http://neo4j.com/docs/stable/query-create-unique.html
what confuses me is, why must there exact node-match before match...merge
/match...create unique
query can return rows? doesn't defeat purpose of query itself?... on create aspect?
i created node follows
create (member:member) return member
then attempted following query - knowing now, member
node exist, though without properties(e.g id
shown below)
match (member:member {id:1}) create unique (member) -[memberof:is_member_of {time:timestamp()}]-> (circle:circle {id:3, cycleid:5, creator:member.id}) return member, circle, memberof
i believe should search member node id = 1... wouldn't exist, should go ahead , create new member
node it's properties, plus defined relationship(s), plus other required node(s).
to surprise, still returns (no rows).
so, please i'll appreciate if points me towards achieving stated aim, explaining me why i've attempted won't work , why proposed solution work.
thanks.
you want connect 2 members via inviation node.
match (circle:circle {id:3, cycleid:5}) match (member1:member {id:1}) match (member2:member {id:2}) create (invite:invite {time:timestamp()})-[:to_circle]->(circle) create (invite)-[:invited_by]->(member1) create (invite)-[:invited]->(member2) return member1, member2, invite, circle;
otherwise if want record fact:
match (circle:circle {id:3, cycleid:5}) match (member1:member {id:1}) match (member2:member {id:2}) merge (member1)-[r:member]->(circle) on create set r.since = timestamp(), r.by = member2.id
Comments
Post a Comment