document.delete()

Learn: Documents

Signature

delete() => <NullDoc>

Description

Deletes a collection document.

Parameters

None

Return value

Type Description

<NullDoc>

Document doesn’t exist.

The data type is taken from the collection’s name with the Null prefix. For example, a NullDoc for the Product collection has the NullProduct type. 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()
  |             ^^^^^^^^^^
  |
\