O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deleting a document in CouchDB using Node.js and Cradle

To remove a record, you use the Cradle module's remove method and pass the ID of the document you want to remove.

How to do it...

Here's an example of remove:

db.remove(id);

Passing an ID removes the document with the given ID.

There's more…

If you have more than one document to remove, you could iterate across all documents, the way the following code does, removing each document in turn:

db.all(function(err, doc) {
  for(var i = 0; i < doc.length; i++) {
    db.remove(doc[i].id, doc[i].value.rev, function(err, doc) {
      console.log('Removing ' + doc._id);
    });
  }
});

This is a more complex use of remove; it takes the document's ID, the revision of the document, and a callback function, which logs to the

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required