document.exists()

Test if a document exists.

Signature

exists() => Boolean

Description

The exists() method tests if a document instance exists.

Use exists() to find if the document can be read. If exists() returns false, there is a corresponding cause field that indicates the reason that the document can’t be read. Possible reasons are:

  • Not found.

  • Permission denied.

If the exists field isn’t present, the document may or may not exist.

Parameters

None

Return value

Type Description

Boolean

true = The document exists.
false = The document doesn’t exist.

Examples

// Uses the `Product` collection's `byName()` index and
// the `first()` method to get a single document.
let product = Product.byName("cups").first()
product?.exists()
true

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!