I have pouchDB replicated from couchdb (couchappy.com). Replication is not live. I just run it under certain conditions (e.g.load/initialization of application, changing of certain options by end user, etc).

I have deleted some docs in couchdb and those appear as "deleted" in pouchdb. Then I wanted to compact my pouchdb: db.compact() call. But this call seems not to do much for deleted docs.

Note that I have already compacted counchdb.

I am using pouchdb 2.2.0.

Does anyone of you guys know what is compact() call actually doing on pouchdb? Also, how to get rid of the "deleted" docs?

Cheers, Alberto

有帮助吗?

解决方案

CouchDB and PouchDB always keep a "tombstone" revision for deleted documents, because otherwise funky things would happen during replication. So those deleted docs don't go away during compaction; compaction just gets rid of any revisions older than the most recent one.

There is also a "purge" command that can really eliminate a document and its history, but it's pretty drastic, and most of the time you don't want to do it unless you have to (source). Also, it's not supported in PouchDB yet, although it's in progress.

If you're just worried about a doc taking up space, instead of simply calling pouch.remove(), you can do:

pouch.get('mydoc').then(function (doc) {
  var deletedDoc = {
    _id      : doc._id,
    _rev     : doc._rev,
    _deleted : true
  };
  return pouch.put(doc);
}).then(function (res) {
  // etc.
}).catch(function (err) {
  // etc.
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top