Reputation: 4328
I'm trying to fill in my understanding of the fundamentals of neo4j (version 3.4).
I believe that all of the following produce the same results -- ie they are different syntax for doing exactly the same thing:
MATCH (ee {name: "Emil"}) RETURN ee;
MATCH (ee) WHERE ee.name = "Emil" RETURN ee;
MATCH (ee:Person {name: "Emil"}) RETURN ee;
MATCH (ee:Person) WHERE ee.name = "Emil" RETURN ee;
MATCH (ee:Person) WHERE (ee).name = "Emil" RETURN ee;
I actually have several questions:
Among this list is there a "best" way of doing a Node
MATCH
? Obviously using a :Label
makes it more efficient, but the effect of WHERE
vs prop maps is mysterious.
Are any of these out-right incorrect? That is to say that although they work, it's kind of unintended or a particularly bad pattern.
Are there additional ways of making a MATCH
operation, further to this list? I'm curious for an exhaustive list (wrong or right).
Upvotes: 1
Views: 41
Reputation: 793
For an exhaustive list, you might include:
MATCH (ee) WHERE ee.name in ["Emil"] RETURN ee
This is not particularly helpful with a single item, but you can have multiple comma delimited items in a list or a collection. For example,
match (n:order{item:'widget'})
with collect(distinct n.customer_id) as customerCollection
match (c:Customers) where c.customer_id in [customerCollection]
return c.Name, c.City
Upvotes: 1
Reputation: 67019
Your clauses are NOT all the same.
The first group of (2) MATCH
clauses DO NOT require the Person
label for matched nodes. But the second group of (3) clauses DO require the Person
label.
Putting a label (or many labels, as appropriate) on a node is generally a good idea, as matching on a label is a quick way to filter your nodes when performing a MATCH
. And labels also aid in data model understandability. In addition, a label is required if you wanted to index a node property.
But whether or not you should specify a label (or several) on a specific a MATCH
clause depends on the amount of filtering you are trying to do. Omitting all labels from a MATCH
would be perfectly appropriate if at that point in your query you really wanted to match nodes with any label (or even no labels).
Upvotes: 1