# Collection.delete()

Deletes all objects in the query.

#### Syntax

```
collection.delete()
```

#### Return Value

Promise where result is the Number of deleted records.

#### Error Handling

If any object fails to be deleted or an exception occurs in a callback function, the entire operation will fail and the transaction will be aborted.

If you catch the returned Promise, the transaction will not abort, and you recieve a Dexie.MultiModifyError error object containing the following properties:

| failures     | Array of Error objects for all errors that have occurred                                                                                                              |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| failedKeys   | Array with the keys of the failed deletions. This array will have the same order as failures so that failures\[i] will always represent the failure of failedKeys\[i] |
| successCount | Number of successful deletions made.                                                                                                                                  |

If you do NOT catch the returned Promise, and an error occurs, the transaction will be aborted.

If you want to log the error but still abort the transaction, you must encapsulate the operation in a transaction() block and catch the transaction instead. It is also possible to catch the operation and call transaction.abort() in the catch() clause.

#### Sample

```javascript
db.orders
    .where("state").anyOf("finished", "discarded")
    .or("date").below("2014-02-01")
    .delete()
    .then(function (deleteCount) {
        console.log( "Deleted " + deleteCount + " objects");
    });
```

With yield (Supported since 2015 by Chrome, Firefox, Opera and Edge):

```javascript
db.transaction('rw', db.orders, function* () {
    var deleteCount = yield db.orders
        .where("state").anyOf("finished", "discarded")
        .or("date").below("2014-02-01")
        .delete();

    console.log ("Successfully deleted " + deleteCount + " items");
}).catch (e => {
    console.error (e);
});
```

With Typescript:

```javascript
async function myDeleteFunction () {
    let deleteCount = await db.orders
        .where("state").anyOf("finished", "discarded")
        .or("date").below("2014-02-01")
        .delete();
}
```

#### Remarks

Collection.delete() is equivalent to:

```javascript
Collection.modify(function () {delete this.value;});
```

..but Collection.delete() is much faster than deleting using Collection.modify().


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dexiejs.typogram.co/collection/collection.delete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
