简体   繁体   中英

Neo4j - use a property to start a match (REST, Rails, Neo4j 1.98)

I want to store node ids in a node for the purpose of caching (For performance reasons - I'm using a linked list which can slow some operations down).

So something like

start n=node(1432), author=node(n.author_id)
match author-[:WROTE]-book
return book

Or something like

start n=node(1432)
with n.author_id match node(n.author_id)-[:WROTE]-book
return book

Now, this might be unorthodox, but again I'm just caching the most recent ID of a user entry into the system. When there are hundreds or thousands of relationship, it's just quicker to know what node to start from instead of traversing them to find the node to start with.

I could use parameters but I'm using rest and don't want to have to make 100 rest calls to return 100 of the most recent entries. I'd rather Cypher tackle it all in one trip.

Is this possible?

When relying on node ids be aware that they may be reclaimed when nodes are deleted.

In Neo4j 2.1 the following should work:

START n=node(1432)
WITH n
MATCH (other)-[:WROTE]->(book)
WHERE id(other)=n.author_id
RETURN book

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM