Best Practice for CouchDB Document Versioning [closed]

纵然是瞬间 提交于 2020-01-01 03:15:28

问题


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.

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.

Example

The pointer document

{
    "_id" : "document1",
    "versions" : [ "document1/308ef032a3801a" ]
}

The version document

{
    "_id" : "document1/308ef032a3801a",
    ... actual content
}

回答1:


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"
    }
  }
}

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).




回答2:


Here is some discussion about document versioning approaches:

http://jchrisa.net/drl/_design/sofa/_list/post/post-page?startkey=%5B%22Versioning-docs-in-CouchDB%22%5D

The one suggested approach is to stick older versions as attachments to the current doc. As the document mentions, it is simple, scalable, and replicates. The jquery couchdb library has this baked in which is nice.



来源:https://stackoverflow.com/questions/8274762/best-practice-for-couchdb-document-versioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!