Reputation: 31
I am very new to CouchDB. Missing SQL already.
Anyways, I need to create a view that emits a few attributes of my documents along with all the revision IDs.
Something like this
function(doc) {
if (doc.type == 'template') {
emit(doc.owner, {_id: doc._id, _rev: doc._rev, owner: doc.owner, meta: doc.meta, key: doc.key, revisions_ids: What goes here?});
}
}
But how do I tell it to include all the revisions?
I know I can call http://localhost:5984/main/94c4db9eb51f757ceab86e4a9b00cddf
for each document (from my app), but that really does not scale well.
Is there a batch way to fetch revision info?
Any help would be appreciated!!
Upvotes: 3
Views: 5799
Reputation: 28439
CouchDB revisions are not intended to be a version control system. They are only used for ensuring write consistency. (and preventing the need for locks during concurrent writes)
That being said, only the most recent _rev
number is useful for any given doc. Not only that, but a database compaction will delete all the old revisions as well. (a compaction is never run automatically, but is should be part of routine maintenance)
As you may have already noticed, your view outputs the most recent _rev
number in the value
of your view output. Also, if you are using include_docs=true
, then the _rev
number is also shown in the doc
portion of your view result.
Strategies do exist for using CouchDB for revision history, but they are generally complicated, and not usually recommended. (check out this question and this blogpost for more information on that subject)
Upvotes: 7