byId()

Get a document by its document ID.

Signature

byId(id: id | Int ): <Document> | Null<Document>

Description

Gets a document in the collection by its document ID or Int ID value used to create the document.

Parameters

Parameter Type Required Description

id

String or Int

Yes

ID of the document to get.

Return value

One of:

Type Description

Document

Document objects.

Null<Document>

Document doesn’t exist or is inaccessible. See NullDoc.

Examples

Get document by ID:

Product.byId("392886847463751746")
{
  id: "392886847463751746",
  coll: Product,
  ts: Time("2099-04-10T14:31:37.310Z"),
  name: "limes"
}

 

Get document by Int value assigned to id:

let id = 55555
Product.create({ id: id })
Product.byId(id)
{
  id: "55555",
  coll: Product,
  ts: Time("2099-04-10T14:47:33.086Z")
}

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!