如何获取在neo4j中创建的最后一个节点? [英] How to get last node created in neo4j?

查看:290
本文介绍了如何获取在neo4j中创建的最后一个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道您在创建节点时neo4j的每个节点都有一个UUID.我知道您可以通过访问ID来通过该UUID访问特定的节点.例如:

So I know when you created nodes neo4j has a UUID for each node. I know you can access a particular node by that UUID by accessing the ID. For example:

START n=node(144) RETURN n;

START n=node(144) RETURN n;

如何获取最后创建的节点?我知道我可以显示所有节点,然后在具有相应ID的anotehr查询中运行相同的命令,但是有没有办法快速做到这一点?我可以按ID排序节点并限制1个节点吗?有没有更简单的方法?无论哪种方式,我都没有通过简单的密码查询来解决.

How would I get the last node that was created? I know I could show all nodes and then run the same command in anotehr query with the corresponding ID, but is there a way to do this quickly? Can I order nodes by id and limit by 1? Is there a simpler way? Either way I have not figured out how to do so through a simple cypher query.

推荐答案

每次都不保证新节点的ID总是比以前创建的所有节点大,

Every time not guaranteed that a new node always has a larger id than all previously created nodes,

所以更好的方法是设置created_at属性,该属性在创建节点时存储当前时间戳. 您可以使用timestamp()函数存储当前时间戳记

So Better way is to set created_at property which stores current time-stamp while creating node. You can use timestamp() function to store current time stamp

然后

Match (n)
Return n
Order by n.created_at desc
Limit 1

这篇关于如何获取在neo4j中创建的最后一个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆