June 2015
Intermediate to advanced
192 pages
4h 8m
English
To remove a record, you use the Cradle module's remove method and pass the ID of the document you want to remove.
Here's an example of remove:
db.remove(id);
Passing an ID removes the document with the given ID.
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
Read now
Unlock full access