Skip to content

WriteableCollection.delete()

David Fahlander edited this page Apr 10, 2014 · 29 revisions

Deletes all objects in the query.

Syntax

collection.delete()

Return Value

Promise where result is an array of arrays [key, value] of all deleted objects. If any object fails to delete, entire operation will fail and transaction aborted unless the returned Promise is catched.

Sample

db.orders.where("state").anyOf("finished", "discarded").or("date").below("2014-02-01").delete()
         .then(function (deletedOrders) {
             console.log( JSON.stringify(deletedOrders) ):
         });

Remarks

This method is equivalent to the following:

var deletedRecords = [];
collection.each(function (item, cursor) {
    deletedRecords.push([cursor.key, cursor.value]);
    cursor.delete();
}).then (function () {
    return deletedRecords;
});
Clone this wiki locally