如何使用 neo4j 实施修订? [英] How do I implement revisions with neo4j?

查看:15
本文介绍了如何使用 neo4j 实施修订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,我需要保留对其所做的所有更改的历史记录.我将如何使用 neo4j 实现这一点?

I have an object and I need to keep a history of all changes made to it. How would I implement this using neo4j?

推荐答案

与 RDBMS 一样,它取决于您的域和数据查询要求.

As with a RDBMS, it would depend on your domain and data query requirements.

您的应用程序是否需要定期访问对象的所有版本,还是通常只访问最新版本,旧版本可通过当前版本访问?这方面的一个例子可能是维基百科上的页面.例如,假设我们有一个版本为 3 的页面.然后我们可以如下建模:

Does your application require regular access to all versions of the object or usually just to the most recent, with the older versions available via the current one? An example of this could be pages on Wikipedia. As as example, let's say we have a page which is on version 3. We could then model this as follows:

(pages)-[:PAGE]->(V3)-[:PREV]->(V2)-[:PREV]->(V1)
   ^               ^
   |               |
category        current
  node      version of page

在这里,只能看到当前版本构成主要结构的一部分,但您可能希望允许所有版本构成该结构的一部分.在这种情况下,您可以使用关系属性来指示版本并从类别节点链接所有页面版本:

Here, only the current version can be seen to form part of the main structure but you may wish to allow all versions to form part of that structure. In this case, you could use relationship properties to indicate the version and have all page versions link from the category node:

  (V1)
    ^
    |
[:PAGE(v=1)]
    |
 (pages)-[:PAGE(v=2)]->(V2)
    |
[:PAGE(v=3)]
    |
    v
  (V3)

在这里,您只需指定您感兴趣的版本即可立即遍历到页面的特定版本.

Here, you can immediately traverse to a particular version of the page by simply specifying the version in which you are interested.

第三种选择可能是您希望所有旧版本与主结构完全分离.为此,您可以使用多个类别节点,一个用于 (current_pages),另一个用于 (old_pages).由于每个页面都被新版本取代,它与前一个类别断开链接,而是链接到后者.这将形成更多的归档"类型系统,其中旧版本甚至可以移动到单独的数据库实例中.

A third option could be that you wish all older versions to be completely separate from the main structure. For this you could use multiple category nodes, one for (current_pages) and another for (old_pages). As each page is superseded by a new version, it becomes unlinked from the former category and instead linked to the latter. This would form more of an "archive" type of system where the older versions could even be moved into a separate database instance.

所以你有这三个选项,还有更多我没想到的!Neo4j 允许您通过这种设计获得极大的灵活性,并且绝对没有正确"的答案.但是,如果这些都没有激发您的灵感,请发布更多有关您的域的信息,以便更适合您的需求的答案.

So you have these three options, plus more that I haven't thought of! Neo4j allows you great flexibility with this sort of design and there's absolutely no "right" answer. If none of these inspire you however, post a little more information about your domain so that the answer can be more tailored for your needs.

干杯,尼哥

这篇关于如何使用 neo4j 实施修订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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