CouchDB文档版本控制的最佳实践 [英] Best Practice for CouchDB Document Versioning
问题描述
在我的问题之后
Following my question here I am exmploring ideas for a generic approach to document versioning in CouchDB. While I imagine there may be no canonical approach, I had the following idea and am looking for feedback.
我想尽可能地维护可读文档ID,因此位于document1
的文档将包含指向系统上所有现有版本的 pointer 文档.实际的修订文档将位于document1/308ef032a3801a
之类的位置,
308ef032a3801a
是一些随机数或哈希.
I would like to maintain readable document ids as much as possible, so a document existing at document1
would contain a pointer document to all existing versions on the system. The actual revision documents would be at something like document1/308ef032a3801a
where
308ef032a3801a
is some random number or hash.
指针文档
{
"_id" : "document1",
"versions" : [ "document1/308ef032a3801a" ]
}
版本文档
{
"_id" : "document1/308ef032a3801a",
... actual content
}
推荐答案
更常见的是将文档的旧版本保留在当前修订版中(以JSON或通常为附件的形式).对于JSON情况;
It's more typical to keep older versions of your document inside your current revision (either as JSON or, often, as an attachment). For the JSON case;
{
"_id":"foo",
"_rev":"3-fsfsfsdf",
"foo":"current value of foo",
"history": {
"2": {
"foo":"previous version of foo"
},
"1": {
"foo":"initial version of foo"
}
}
}
显然,这使事情有些混乱,这就是为什么将文档的完整旧版本放入附件中通常更简单的原因.这种模式非常常见,以至于CouchDB附带了一个库jquery.couch.js
来实现它(在saveDoc(doc)
函数中).
Obviously this clutters things somewhat, which is why it's often simpler to push the full old version of the document into an attachment instead. This pattern is common enough that CouchDB ships with a library, jquery.couch.js
, that implements it (in the saveDoc(doc)
function).
这篇关于CouchDB文档版本控制的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!