delete()

Delete a document.

Signature

delete(): Null<collection> | NullCollectionDef

Description

The delete() method deletes the collection document or collection definition document from storage.

Parameters

None

Return value

Type Description

Null<collection>
NullCollectionDef

See NullDoc

Examples

The document exists:

// Uses the `Product` collection's `byName()` index and
// the `first()` method to get a single document.
let product = Product.byName("cups").first()
product!.delete()
Product("401604133308596297") /* deleted */

The document doesn’t exist:

Product.byId("401604133308596297")!.delete()
document_not_found

error: Collection `Product` does not contain document with id 401604133308596297.
at *query*:1:13
  |
1 | Product.byId("401604133308596297")!.delete()
  |             ^^^^^^^^^^^^^^^^^^^^^^^
  |

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!