incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anand Chitipothu <>
Subject behavior of document revisions
Date Thu, 19 Mar 2009 00:53:13 GMT
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.


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]?


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


* get latest version of a page:
* 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?


View raw message