Neo4j cypher query: get last N elements

前端 未结 1 372
不思量自难忘°
不思量自难忘° 2021-01-23 22:41

I have a graph that contains a relationship between users, showing what user has visited another\'s profile, and when:

(visitor:User)-[:VISITED]->(visitee:Use         


        
1条回答
  •  鱼传尺愫
    2021-01-23 23:09

    The simplest would be to use an ORDER BY and a LIMIT before the DELETE. I.e.:

    MATCH (visitor:User)-[r:VISITED]->(User)
    WHERE visitor.user_id = %s
    WITH r ORDER BY r.date LIMIT 1
    DELETE r
    

    A more efficient mechanism may be to keep a linked list of visit (there's some discussion on this here: http://docs.neo4j.org/chunked/stable/cypherdoc-linked-lists.html)

    0 讨论(0)
提交回复
热议问题