0
votes

Basically I want to sort between various nodes and return one latest, whose property is true.. but if true is not present, I should get latest node having false property.
for e.g.
nodeA - > having property renamed value is true
nodeB - > having property renamed value is false

now the scenario is, there could be n number of nodes with property renamed as true and false, I want just latest one (node also have property of time in millisecond format) with property of true if not true then latest false.

is there any way to achieve this using cypher query ? Thanks

2

2 Answers

1
votes

If I understand your question correctly, you want the latest node with the property "renamed" value of "true", then you can first sort the nodes by the property "renamed" and then the property "time" in descending order, and take the first one,

Match somenode:Something
Return somenode
Order by somenode.renamed DESC, somenode.time DESC 
limit 1

If there are nodes with the property "renamed" value of "true", then the first one must be the latest one of all nodes with the value "true"; if there are no nodes with the value of "true", then the first one must be the latest one of all nodes with the value of "false".

-1
votes
START a=node(*) 
MATCH p=a-[*1..]->b 
WHERE ALL (x IN nodes(p) 
           WHERE x.renamed=true OR (id(x)=id(b) AND x.renamed=false)) 
RETURN p

all nodes except the last one b must have renamed=false and the last one b must have renamed=false