I came across an earlier discussion on "behavior of document
revisions"[1], which says that:
> A revision in CouchDB is meant to be used to test if a document has
> changed since the last time you looked (useful for async updates
> example) and not to actually look back in time at the document.
[1]: http://osdir.com/ml/db.couchdb.devel/2008-01/msg00123.html
Does it mean that if I want to create a wiki, I have to manage my own
document revisions? Like shown in this blog post[2]?
[2]: http://prematureoptimization.org/blog/archives/59
I tried to extend the wiki idea in [2].
Here are my views assuming that every page has path, title, body and revision.
{
"_id": "_design/wiki",
"language": "javascript",
"views": {
"page": {
"map": "function(doc) { emit([doc.path, doc.revision], doc)}"
},
"by_title": {
"map": "function(doc) { emit(doc.title, doc)}",
"reduce": "function(key, values, rereduce) { var doc =
{'revision': 0}; for (var i in values) if (values[i].revision >
doc.revision) doc = values[i]; } return doc; }"
}
}
}
Actions:
* get latest version of a page:
/wiki/_design/wiki/_view/page?startkey=["foo",
"Z"]&descending=true&limit=1
* get an old version of a page: /wiki/_design/wiki/_view/page?key=["foo", 2]
* find pages with given title: /wiki/_design/wiki/_view/by_title?key="foo"
Is this is the right approach?
I'm not quite happy with the above implementation of by_title as it is
indexing all the revisions, which is unnecessary.
Is it not possible to create a view using only the latest version of pages?
Thanks,
Anand
|