MongoDB中文档集的版本控制 [英] Versioning of sets of documents in MongoDB

查看:186
本文介绍了MongoDB中文档集的版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在MongoDB服务器中对单个文档进行版本控制的几种方法。但是,我想添加单个文档的版本控制和整个集合的版本控制。也就是说如果文档A从版本1更改为2,我还想知道A是什么版本2,文档B,C,D等什么版本。

I am aware of several approaches to versioning individual documents in a MongoDB server. I'd like, however, to add both versioning of individual documents and versioning of entire sets. I.e. if document A changes from version 1 to 2, I'd also like to know what when A is at version 2, what versions are documents B, C, D, etc.

这里的基本目标是数据源。假设我对一组文档D有一个查询Q,生成结果R.我想保存D + Q = R,所以当D因为文档改变而变成D'时,我有D'+ Q = R' 。

The underlying goal here is data provenance. Say I have a query Q on a set of documents D, generating result R. I'd like to save D+Q=R, so when D becomes D' because a document has changed, I have D'+Q=R'.

在MongoDB中做最好的策略的任何想法?我可以保留具有所有其他文档版本的单独的文档,但对于运行查询似乎非常昂贵。我可以使用时间戳而不是版本,这可能工作正常。在MongoDB中有没有我不知道这种事情的支持。

Anythoughts on the best strategy for doing this in MongoDB? I can keep separate documents that has versions of all other documents, but that seems very expensive to run queries against. I can use timestamp rather than versions, which may work okay. Are there supports for this kind of thing in MongoDB that I am not aware of?

谢谢。

推荐答案

在MongoDB中没有特别支持这样的功能,你必须在应用程序代码中实现它。它听起来像你有一个反规范模式:R实际上是Q的缓存,你必须在D更改时无效。您可以同步执行此失效,当您更新D中的任何文档,或者您可以安装一些任务队列(例如RabbitMQ)并插入一个任务,当您更改D,并有一个后台进程从队列拉任务。后台进程然后更新R.具体实现取决于你需要R的一致性。

There's no specific support for a feature like this in MongoDB, you'll have to implement it in your application code. It sounds like you have a denormalization pattern: R is effectively a cache of Q that you must invalidate when D changes. You can either do this invalidation synchronously, when you update any documents in D, or you can install some task queue (e.g. RabbitMQ) and insert a task into it whenever you change D, and have a background process pull tasks from the queue. The background process then updates R. The specific implementation depends on how consistent you need R to be.

这篇关于MongoDB中文档集的版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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