Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-29-2020 08:55 PM
I am new to neo4j, and am just following the example from the docs:
neo4j@neo4j> CREATE (john:Person {name: 'John'})
CREATE (joe:Person {name: 'Joe'})
CREATE (steve:Person {name: 'Steve'})
CREATE (sara:Person {name: 'Sara'})
CREATE (maria:Person {name: 'Maria'});
0 rows available after 55 ms, consumed after another 0 ms
Added 5 nodes, Set 5 properties, Added 5 labels
neo4j@neo4j> MATCH (n) RETURN n;
+---------------------------+
| n |
+---------------------------+
| (:Person {name: "John"}) |
| (:Person {name: "Joe"}) |
| (:Person {name: "Steve"}) |
| (:Person {name: "Sara"}) |
| (:Person {name: "Maria"}) |
+---------------------------+
5 rows available after 16 ms, consumed after another 5 ms
Note that there are no node names here. So when I try to create relationships, it can't find the nodes and creates new (blank) nodes:
neo4j@neo4j> CREATE (john)-[:FRIEND]->(joe)-[:FRIEND]->(steve)
CREATE (john)-[:FRIEND]->(sara)-[:FRIEND]->(maria);
0 rows available after 39 ms, consumed after another 0 ms
Added 5 nodes, Created 4 relationships
neo4j@neo4j> MATCH (n) RETURN n;
+---------------------------+
| n |
+---------------------------+
| (:Person {name: "John"}) |
| (:Person {name: "Joe"}) |
| (:Person {name: "Steve"}) |
| (:Person {name: "Sara"}) |
| (:Person {name: "Maria"}) |
| () |
| () |
| () |
| () |
| () |
+---------------------------+
10 rows available after 2 ms, consumed after another 1 ms
I can see in the web browser that the blank nodes are all connected, and the named nodes are unconnected.
neo4j@neo4j> call dbms.components() yield name, versions, edition unwind versions as version return name, version,
edition;
+----------------------------------------+
| name | version | edition |
+----------------------------------------+
| "Neo4j Kernel" | "4.2.1" | "community" |
+----------------------------------------+
Any help would be greatly appreciated.
12-29-2020 09:32 PM
CREATE (joe:Person {name: 'Joe'})
Here:
'joe' is an alias name and you can have any name
'Person' is the node name (or node label)
This is what you see when you ran MATCH(n) RETURN n
12-29-2020 09:40 PM
Thanks. I think I see the problem now. The CREATE relationships have to be done in the same statement as CREATE nodes (where the aliases are introduced).
12-30-2020 01:28 AM
Hi @ben5,
Few suggestions,
CREATE -> I executed Create 2 times with the same properties, and the result is 2 nodes
CREATE (john:Person {name: 'John'});
Added 1 label, created 1 node, set 1 property, completed after 3 ms.
CREATE (john:Person {name: 'John'});
Added 1 label, created 1 node, set 1 property, completed after 3 ms.
match (n) return (n)
╒═══════════════╕
│"n" │
╞═══════════════╡
│{"name":"John"}│
├───────────────┤
│{"name":"John"}│
└───────────────┘
MERGE -> I execute MERGE with the same properties, but no duplicate nodes are created.
MERGE (john:Person {name: 'John'})
Added 1 label, created 1 node, set 1 property, completed after 3 ms.
MERGE (john:Person {name: 'John'})
(no changes, no records)
MERGE (john:Person {name: 'John'})
(no changes, no records)
MERGE (john:Person {name: 'John'})
(no changes, no records)
match (n) return (n)
╒═══════════════╕
│"n" │
╞═══════════════╡
│{"name":"John"}│
└───────────────┘
MERGE (john:Person {name: 'John'})
MERGE (joe:Person {name: 'Joe'})
MERGE (steve:Person {name: 'Steve'})
MERGE (sara:Person {name: 'Sara'})
MERGE (maria:Person {name: 'Maria'})
MERGE (john)-[:FRIEND]->(joe)-[:FRIEND]->(steve)
MERGE (john)-[:FRIEND]->(sara)-[:FRIEND]->(maria);
Just make sure the "variable" names are matched within a single transactions.
Hope this works ...
12-30-2020 10:39 AM
Here WITH is not required. It works even without WITH.
WITH is required if a MERGE statement follows a MATCH statement.
All the sessions of the conference are now available online