Select
Select( path, from, default )
Description
The Select
function extracts a single value from a document. It
extracts the value specified by the path
parameter out of the from
parameter and returns the value. If the path
does not exist, the
optional default
object is returned. If the default object is not
provided, an error is returned.
Parameter
Argument | Type | Definition and Requirements |
---|---|---|
|
Long or String |
The path to a field in the document to extract. |
|
Object |
The object containing the data to be extracted. |
|
Object |
Optional - The value to be returned if the path does not exist. |
Examples
The query below extracts from the top level object named "favorites" and second level array called "foods" the value in position 1 of the array. This value is "munchings".
client.query(
q.Select(
['favorites', 'foods', 1],
{ favorites: { foods: ['crunchings', 'munchings', 'lunchings'] } },
)
)
.then((ret) => console.log(ret))
munchings
In the example below select
extracts the "id" attributes from the
Ref.
client.query(q.Select(['id'], q.Database('prydain')))
.then((ret) => console.log(ret))
prydain
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!