Select
|
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Select( path, from, [ default ] )
select( path, from, [ default ] )
Select( path, from, [ default ] )
Select( path, from, [ default ] )
Select( path, from, [ default ] )
Select( path, from, [ default ] )
Description
The Select function extracts a single value from a document. It
extracts the value identified by the path parameter out of the from
parameter and returns the value. If the path does not exist, the
optional default value is returned. If the path does not exist and
the default value is not provided, an error is returned.
Paths
The path parameter defines which part of from should be selected and
returned.
-
If
fromis an Array,pathcan be expressed as a Long which is interpreted a the zero-based index from the start of the array. For example:Select(2, ['one', 'two', 'three', 'four'])'three' -
If
fromis an Object,pathcan be expressed as a String, which is interpreted as the name of a field infrom. For example:Select('b', {a: 'one', b: 'two', c: 'three'})'two' -
If
fromis an Object that has nested objects,pathcan be expressed as an Array that has field names, or array offsets, that lead to the value in the structure offrom. For example:Let( { from: { timestamp: Now(), leaders: [ { player: 'eskwayrd', position: [53, 47], score: 11, }, { player: 'databrecht', position: [11, 22], score: 10, }, { player: 'n400', position: [37, 4], score: 7, }, ], } }, Select(['leaders', 1, 'position', 1], Var('from')) )22
Parameter
| Parameter | Type | Definition and Requirements |
|---|---|---|
|
Array, Long, or String |
The field name path (the list of field names or array offsets required
to access a specific field nested in the document structure), array
offset, or field name in |
|
Array or Object |
The value with the data to be selected. |
|
Any |
Optional - The value to be returned if the To express this parameter, use the Go-only |
Examples
-
The following query 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."
munchingsmunchingsmunchingsStringV(munchings)"munchings"'munchings' -
The following query uses
Selectto extract the document ID from the Reference:prydainprydainprydainStringV(prydain)"prydain"'prydain' -
The following query demonstrates how the
defaultvalue is returned when thepathis not found infrom:The defaultThe defaultThe defaultStringV(The default)"The default"'The default'