collection.byId()

Get a document by its document ID.

Signature

byId(id: ID | Long | String ): <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

ID | Long | String

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("401697070347452493")
{
  id: "401697070347452493",
  coll: Product,
  ts: Time("2099-06-25T20:23:49.070Z"),
  name: "cups",
  description: "Translucent 9 Oz, 100 ct",
  price: 698,
  stock: 90,
  category: Category("401697070344306765")
}

 

Get document by Int value assigned to id:

let id = 55555
let produce = Category.byName("produce").first()
Product.create({
  id: id,
  name: "key lime",
  description: "Organic, 1 ct",
  price: 79,
  category: produce,
  stock: 2000
})
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!