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:

Letter.byId("357101842659803169")
{
  id: "357101842659803169",
  coll: Letter,
  ts: Time("2023-02-19T14:41:45.693Z"),
  name: "B"
}

 

Get document by Int value assigned to id:

let id = 55555
MyColl.create({ id: id })
MyColl.byId(id)!
{
  id: "55555",
  coll: MyColl,
  ts: Time("2024-01-02T22:06:37.460Z")
}

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!