I've noticed that the size of my DB is increasing after deleting / restoring docs with auto-compaction set to true. What do I do wrong?
Here is my code:
var db = new PouchDB("myDB", {adapter: "idb", auto_compaction: true});
var docs = [{_id: "0", name: "foo1"}, {_id: "1", name: "foo2"}];
db.bulkDocs(docs).then(function() {
db.allDocs({include_docs: true}).then(function(result) {
docs = result.rows.map(function(row) {
return row.doc;
});
};
};
function remove() {
for (var i in docs) {
docs[i]._deleted = true;
}
return db.bulkDocs(docs);
};
function restore() {
for (var i in docs) {
delete docs[i]._deleted;
delete docs[i]._rev;
}
return db.bulkDocs(docs);
}
// Calling this function increases the size of the DB
function test() {
return remove(docs).then(restore);
}
That's not the correct way to delete documents from PouchDB.
Use:
db.remove(doc, [options], [callback])Please check here
Good luck