Get
Get( ref, [ts] )
Description
The Get
function retrieves a single document identified by
ref
. An optional timestamp (ts
) can be
provided to retrieve the document which existed at the specific date and
time. If the timestamp is omitted the default is the current time.
Get
is also useful for retrieving the first document from a
Match
result.
Parameter
Argument | Type | Definition and Requirements | ||
---|---|---|---|---|
|
A document reference that uniquely identifies a document. |
|||
|
Optional - Return the document at the specified point in time (number of UNIX microseconds or Timestamp). The default is the current time.
|
Returns
A document containing both the document data and metadata described below.
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
The reference identifies the document retrieved. |
|
|
The document data retrieved at the location pointed to by ref. |
|
|
The timestamp associated with the creation of the requested document
version, according to the |
Examples
The following query retrieves an document by providing a reference to the collection named "spells" at a specific id:
client.query(
q.Get(q.Ref(q.Collection('spells'), '181388642046968320'))
)
.then((ret) => console.log(ret))
{ ref: Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
ts: 1526677786695156,
data:
{ name: "Fire Beak",
element: [ "air", "fire" ],
spellbook: Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections))) } }
To retrieve multiple references in a single operation, utilize the array operator to group and return multiple documents. The following example returns three different identifiers from the spells collection in a single database operation. This saves network bandwidth and processing by grouping several requests for data into the same operation.
client.query([
q.Get(q.Ref(q.Collection('spells'), '181388642046968320')),
q.Get(q.Ref(q.Collection('spells'), '181388642071085568')),
q.Get(q.Ref(q.Collection('spells'), '181388642088911360')),
])
.then((ret) => console.log(ret))
[ { ref: Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
ts: 1509244539547758,
data:
{ name: "Fire Beak",
element: [ "air", "fire" ],
spellbook: Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections))) } },
{ ref: Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))),
ts: 1509244539547758,
data:
{ name: "Water Dragon's Claw",
element: [ "water", "fire" ],
spellbook: Ref(id=181388642139243008, collection=Ref(id=spellbooks, collection=Ref(id=collections))) } },
{ ref: Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))),
ts: 1509244539235128,
data:
{ name: "Hippo's Wallow",
element: [ "water", "earth" ] } } ]
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!