1

I'm fiddling around with PouchDB at the moment. I use it as a way to store data locally without it being linked to CouchDB. What I've been trying to do is to create a revert/undo method for a single doc. For this I would like to use the previous revisions of the "doc". I came across the changes feed while reading the PouchDB documentation, which at first seems to be a way to get all the revisions of the all the "docs". However, after trying to get all the revisions of the "docs" I've only got the latest revision. I've tried the following to get the changes:

db.changes({
    since: 0,
    style: 'all_docs',
    include_docs: true // eslint-disable-line camelcase
  }).then(function(results) {
    console.log(results);
  }); 

TL;DR how can I get all the revisions of a (or all) document(s) in PouchDB?

Mathijs
  • 367
  • 1
  • 4
  • 14

2 Answers2

3

With some help of macrog I've found a way to do what I wanted to do. Short summary I wanted a way to get all revisions of my documents, including the ones which had been removed. This is what I use now:

db.get(String(id), {
    revs: true, 
    open_revs: 'all' // this allows me to also get the removed "docs"
  }).then(function(found) {
    console.log(found);
  });

Granted I no loger use db.changes() to get all the revisions of a document. But at least I'm able to do what I wanted to do.

Community
  • 1
  • 1
Mathijs
  • 367
  • 1
  • 4
  • 14
  • hey, good that you have managed to do what you wanted, give a try to @nlawson solution, this guy knows what he's talking about ! :) – macrog Nov 04 '15 at 08:41
1

Try one of the options - this it's from pouchdb docs:

db.get(docId, [options], [callback])

Retrieves a document, specified by docId.

Options All options default to false unless otherwise specified.

options.rev: Fetch specific revision of a document. Defaults to winning revision (see the CouchDB guide).

options.revs: Include revision history of the document.

options.revs_info: Include a list of revisions of the document, and their availability.

options.open_revs: Fetch all leaf revisions if open_revs="all" or fetch all leaf revisions specified in open_revs array. Leaves will be returned in the same order as specified in input array.

Community
  • 1
  • 1
macrog
  • 2,085
  • 1
  • 22
  • 30
  • Thanks, this brought me one step closer. However, it sadly does not help me with deleted/removed "docs". – Mathijs Nov 02 '15 at 10:53
  • No problem, happy to help! How are you deleting docs? with db.remove(...) ?? try to make a put as an update and set **"_deleted":true** I think (not sure) you should get them with _changes – macrog Nov 02 '15 at 11:05
  • I am using db.remove(...), for as far as I know it should not make a difference if I'd do it that way or by doing a db.put({_deleted: true, ...}). Not really sure what you mean with _changes... Would you care to elaborate? – Mathijs Nov 02 '15 at 11:23
  • 2
    You can find removed docs by using the `keys` parameter with `allDocs()`. (Yeah, it's unintuitive, but `keys` will fetch deleted docs, whereas every other option won't.) – nlawson Nov 03 '15 at 21:47