collection.byId()

Get a collection document by its document id.

Signature

byId(id: ID) => <Document> | <NullDoc>

Description

Gets a collection document by its document id.

Parameters

Parameter Type Required Description

id

ID

Yes

The ID must be a Int or String that be coerced into a 64-bit unsigned integer in the 253-1 range.

Return value

One of:

Type Description

Document

Document objects.

NullDoc

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

Examples

Get document by ID:

Product.byId("111")
{
  id: "111",
  coll: Product,
  ts: Time("2099-06-25T20:23:49.070Z"),
  name: "cups",
  description: "Translucent 9 Oz, 100 ct",
  price: 698,
  stock: 100,
  category: Category("123")
}

 

Get document by Int value assigned to id:

let id = 12345
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: "12345",
  coll: Product,
  ts: Time("2099-10-25T16:52:26.510Z"),
  name: "key lime",
  description: "Organic, 1 ct",
  price: 79,
  category: Category("789"),
  stock: 2000
}

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!