在键值存储中保存带有修订的文档的最佳方法是什么?
我是键值存储新手,需要您的推荐。我们正在开发一个管理文档及其修订的系统。有点像维基百科。我们正在考虑将这些数据保存在键值存储中。
请不要给我推荐您喜欢的数据库,因为我们想破解它,以便我们可以使用许多不同的键值数据库。我们使用node.js,因此我们可以轻松地使用json。
我的问题是:数据库的结构应该是什么样的?我们有每个文档的元数据(时间戳、最后文本、id、最新版本),并且我们有每个修订的数据(更改、作者、时间戳等)。那么,您推荐哪种键/值结构?
谢谢
I'm new to Key-Value Stores and I need your recommendation. We're working on a system that manages documents and their revisions. A bit like a wiki does. We're thinking about saving this data in a key value store.
Please don't give me a recommendation that is the database you prefer because we want to hack it so we can use many different key value databases. We're using node.js so we can easily work with json.
My Question is: What should the structure of the database look like? We have meta data for each document(timestamp, lasttext, id, latestrevision) and we have data for each revision (the change, the author, timestamp, etc...). So, which key/value structure you recommend?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
摘自 MongoDB 群组。它有些特定于 MongoDB,但是非常通用。
大多数历史实现都分为两种常见策略。
策略 1:嵌入历史记录
理论上,您可以将文档的历史记录嵌入到文档本身中。这甚至可以原子地完成。
策略 2:将历史记录写入单独的集合
在这里您将看到我执行了两次写入。一件到大师收藏和
一份历史收藏。
要快速查找历史记录,只需获取原始 ID:
历史集合
到原始集合
的链接来进行混合很难说有一个“最好的方法”。显然这里需要做出一些权衡。
嵌入:
单独集合:
Cribbed from the MongoDB groups. It is somewhat specific to MongoDB, however, it is pretty generic.
Most of these history implementations break down to two common strategies.
Strategy 1: embed history
In theory, you can embed the history of a document inside of the document itself. This can even be done atomically.
Strategy 2: write history to separate collection
Here you'll see that I do two writes. One to the master collection and
one to the history collection.
To get fast history lookup, just grab the original ID:
history collection
tooriginal collection
It's hard to say there is a "best way". There are obviously some trade-offs being made here.
Embedding:
Separate collection:
我会在每个文档下保留真实数据的层次结构,并附加修订数据,例如:
然后使用推送操作添加新版本并定期删除旧版本。您可以使用最后一个(或第一个)过滤器在任何给定时间仅获取最新副本。
I'd keep a hierarchy of the real data under each document with the revision data attached, for instance:
Then use the push operation to add new versions and periodically remove the old versions. You can use the last (or first) filter to only get the latest copy at any given time.
我认为有多种方法,而且这个问题很老了,但我会给出我的两分钱,因为我今年早些时候正在研究这个问题。我一直在使用 MongoDB。
就我而言,我有一个用户帐户,然后在不同的社交网络上有个人资料。我们想要跟踪社交网络配置文件的更改并希望对其进行修改,因此我们创建了两个结构来进行测试。两种方法都有一个指向外来对象的 User 对象。我们不想从一开始就嵌入对象。
用户看起来像这样:
然后,对于combo_foreign_key,我们使用了这种模式(为了简单起见,使用 Ruby 插值语法)
这为我们提供了 O(1) 查找用户的最新 FacebookProfile,但要求我们将最新的 FK 存储在用户对象。如果我们想要所有 FacebookProfiles,我们会要求 facebook_profiles 集合中带有“#{User.key}__”前缀的所有键,这是 O(N)...
我们尝试的第二个策略是存储一个数组用户对象上的那些 FacebookProfile 键,因此用户对象的结构从 更改为
这里
,当我们添加新的配置文件变体时,我们只需附加新的组合键。然后我们只需对“facebook_profile”属性进行快速排序,并在最大的属性上建立索引即可获取最新的个人资料副本。此方法必须对 M 个字符串进行排序,然后根据排序列表中最大的项目对 FacebookProfile 进行索引。获取最新副本的速度有点慢,但它给了我们一次性了解用户 FacebookProfile 的每个版本的优势,而且我们不必担心确保foreign_key确实是最新的配置文件对象。
起初,我们的修订次数非常少,而且效果都很好。我想我现在更喜欢第一个而不是第二个。
希望得到其他人关于解决这个问题的方法的意见。另一个答案中建议的 GIT 想法实际上对我来说听起来非常好,对于我们的用例来说会工作得很好......酷。
I think there are multiple approaches and this question is old but I'll give my two cents as I was working on this earlier this year. I have been using MongoDB.
In my case, I had a User account that then had Profiles on different social networks. We wanted to track changes to social network profiles and wanted revisions of them so we created two structures to test out. Both methods had a User object that pointed to foreign objects. We did not want to embed objects from the get-go.
A User looked something like:
and then, for the combo_foreign_key we used this pattern (Using Ruby interpolation syntax for simplicity)
This gave us O(1) lookup of the latest FacebookProfile of a User but required us to keep the latest FK stored in the User object. If we wanted all of the FacebookProfiles we would then ask for all keys in the facebook_profiles collection with the prefix of "#{User.key}__" and this was O(N)...
The second strategy we tried was storing an array of those FacebookProfile keys on the User object so the structure of the User object changed from
to
Here we'd just append on the new combo_key when we added a new profile variation. Then we'd just do a quick sort of the "facebook_profile" attribute and index on the largest one to get our latest profile copy. This method had to sort M strings and then index the FacebookProfile based on the largest item in that sorted list. A little slower for grabbing the latest copy but it gave us the advantage knowing every version of a Users FacebookProfile in one swoop and we did not have to worry about ensuring that foreign_key was really the latest profile object.
At first our revision counts were pretty small and they both worked pretty well. I think I prefer the first one over the second now.
Would love input from others on ways they went about solving this issue. The GIT idea suggested in another answer actually sounds really neat to me and for our use case would work quite well... Cool.