0 votes
in PouchDB by

Delete a document

db.remove(doc, [options], [callback])

Or:

db.remove(docId, docRev, [options], [callback])

Deletes the document. doc is required to be a document with at least an _id and a _rev property. Sending the full document will work as well.

See filtered replication for why you might want to use put() with {_deleted: true} instead.

Example Usage:

db.get('mydoc').then(function(doc) { return db.remove(doc); }).then(function (result) { // handle result }).catch(function (err) { console.log(err); });

Example Response:

{
  "ok": true,
  "id": "mydoc",
  "rev": "2-9AF304BE281790604D1D8A4B0F4C9ADB"
}

You can also delete a document by just providing an id and rev:

db.get('mydoc').then(function(doc) {
  return db.remove(doc._id, doc._rev);
}).then(function (result) {
  // handle result
}).catch(function (err) {
  console.log(err);
});

You can also delete a document by using put() with {_deleted: true}:

db.get('mydoc').then(function(doc) {
  doc._deleted = true;
  return db.put(doc);
}).then(function (result) {
  // handle result
}).catch(function (err) {
  console.log(err);
});

Related questions

0 votes
asked Jun 5, 2020 in PouchDB by AdilsonLima
0 votes
asked Jun 5, 2020 in PouchDB by AdilsonLima
...