Jack Daniel
Jack Daniel

Reputation: 2611

Limitation on Selection of nodes using labels

I want to keep restriction in cypher in selecting alike nodes without knowing the property values.

Let say, I have few nodes with BUYER as labels. And I don't know anything more than that regarding the database. And I wanted to see the list of properties for the BUYER nodes. And, all BUYER nodes have same set of properties. Then, I did this

My Approach:

MATCH (n:Buyer) 
with keys(n) as each_node_keys 
UNWIND each_node_keys as all_keys
RETURN DISTINCT(all_keys)

In my approach I can clearly see that, first line of query, MATCH(n:Buyer) is selecting all the nodes, iterating all the nodes, collecting all the properties and then filtering. Which is not a good idea.

In order to overcome this, I wanted to LIMIT the nodes we are selecting, like instead of selecting all the nodes, How can I restrict it to select only one node and since I don't know any property values, I cannot filter using the property. Once I pick a node then I should not pick further nodes. How can I do that.

Upvotes: 0

Views: 62

Answers (1)

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

If as you said all Buyer nodes have the same property keys, you can just limit the MATCH for one node :

MATCH (n:Buyer)
WITH n LIMIT 1
RETURN keys(n)

Upvotes: 1

Related Questions