apache / nano

Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano
https://github.com/apache/couchdb-nano
Other
1.13k stars 157 forks source link

fetchRevs only fetching latest revision of document #273

Closed embrown30 closed 9 years ago

embrown30 commented 9 years ago

I'm using the following to get all revs of a document but only one rev is returned:

docnames = {keys: ["somedocid"]}
db.fetchRevs(docnames, parms, function(err, docs){
                docs.rows.forEach(function(doc){
                    if(!err){
                        retdocs.push(doc.doc)
                        console.log("fetchRevs: ", doc)
                    }
                    else{
                        console.warn("Error getting revisions from database: ", err)
                    }
                })
                callback(err,retdocs)

            });

I get this returned:

[
    {
        "_id": "2e6c63b6e6fcf9d686be8d32e0001a67",
        "_rev": "3-bca79e466ce6af40cf940518df9f84e7",
        "version": 0,
        "type": "page",
        "description": "page that is free flowing",
        "tennent": "EricabrDynasty",
        "name": null
    }
]

As you can see, _rev starts with three.. so there are other revisions of the document I'm not getting. Is this what the function is supposed to do. Get ALL Revs of the document, not just the latest? Thanks!

jo commented 9 years ago

fetchRevs is similar to fetch, except that include_docs is false.

What you want to achieve is not possible with a single query. However, you can retrieve all revisions of a single document via open_revs set to all:

db.get('somedocid', { open_revs: 'all' })

See CouchDBs documentation for GET /{db}/{docid}.