{"id":8095,"date":"2015-11-26T13:37:39","date_gmt":"2015-11-26T13:37:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-compact-call-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"pouchdb-compact-call-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/pouchdb-compact-call-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"PouchDB compact() call-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c436dec61b906e27c963518d0ef1d972?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>nlawson<\/strong><\/p>\n<p>CouchDB and PouchDB always keep a &#8220;tombstone&#8221; revision for deleted documents, because otherwise funky things would happen during replication. So those deleted docs don&#8217;t go away during compaction; compaction just gets rid of any revisions older than the most recent one.<\/p>\n<p>There is also a &#8220;purge&#8221; command that can really eliminate a document and its history, but it&#8217;s pretty drastic, and most of the time you don&#8217;t want to do it unless you have to (source). Also, it&#8217;s not supported in PouchDB yet, although it&#8217;s in progress.<\/p>\n<p>If you&#8217;re just worried about a doc taking up space, instead of simply calling <code>pouch.remove()<\/code>, you can do:<\/p>\n<pre><code>pouch.get('mydoc').then(function (doc) {\n  var deletedDoc = {\n    _id      : doc._id,\n    _rev     : doc._rev,\n    _deleted : true\n  };\n  return pouch.put(doc);\n}).then(function (res) {\n  \/\/ etc.\n}).catch(function (err) {\n  \/\/ etc.\n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>nlawson CouchDB and PouchDB always keep a &#8220;tombstone&#8221; revision for deleted documents, because otherwise funky things would happen during replication. So those deleted docs don&#8217;t go away during compaction; compaction just gets rid of any revisions older than the most recent one. There is also a &#8220;purge&#8221; command that can really eliminate a document and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8095","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8095"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8095\/revisions"}],"predecessor-version":[{"id":8628,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8095\/revisions\/8628"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}