document.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("111") /* deleted */

The document doesn’t exist:

Product.byId("12345")!.delete()
document_not_found: Collection `Product` does not contain document with id 12345.

error: Collection `Product` does not contain document with id 12345.
at *query*:1:13
  |
1 | Product.byId("12345")!.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!