FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

For more details, review the migration guide. Contact support@fauna.com with any questions.

SelectAll

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

SelectAll( path, from )
select_all( path, from )
SelectAll( path, from )
SelectAll( path, from )
SelectAll( path, from )

Description

The SelectAll function extracts one or more values from a document, Object, or Array. It is very useful when extracting multiple values from an Array. It extracts all of the values specified by the path parameter out of the from parameter and returns the values as an Array. If the path does not exist an empty array is returned.

This function is not comparable to SQL’s SELECT command. If you are looking to fetch documents from a collection, see the Paginate function.

Parameter

Parameter Type Definition and Requirements

path

String

The path to the field in the document to extract

from

Object or Array

The object or array containing the data to be extracted.

Returns

The value(s) specified by the path.

Examples

The following query extracts all of the name fields from the provided array, by using a string-based path:

client.query(
  q.SelectAll(
    ['people', 'name'],
    {
      people: [
        { name: 'Jane' },
        { name: 'John' },
        { name: 'Thomas' },
      ],
    },
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 'Jane', 'John', 'Thomas' ]
result = client.query(
  q.select_all(
    ["people", "name"],
    {
      "people": [
        {"name": "Jane"},
        {"name": "John"},
        {"name": "Thomas"},
      ],
    },
  )
)
print(result)
['Jane', 'John', 'Thomas']
result, err := client.Query(
	f.SelectAll(
		f.Arr{"people", "name"},
		f.Obj{
			"people": f.Arr{
				f.Obj{"name": "Jane"},
				f.Obj{"name": "John"},
				f.Obj{"name": "Thomas"},
			}}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[Jane John Thomas]
try
{
    Value result = await client.Query(
        SelectAll(
            Arr("people", "name"),
            Obj(
                "people", Arr(
                    Obj("name", "Jane"),
                    Obj("name", "John"),
                    Obj("name", "Thomas")
                )
            )
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(StringV(Jane), StringV(John), StringV(Thomas))
SelectAll(
  ['people', 'name'],
  {
    'people': [
      { 'name': 'Jane' },
      { 'name': 'John' },
      { 'name': 'Thomas' },
    ],
  },
)
[ 'Jane', 'John', 'Thomas' ]
Query metrics:
  •    bytesIn: 146

  •   bytesOut:  37

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 6ms

  •    retries:   0

The following query extracts all of the first names from the name fields, by using a path that includes a numeric index:

client.query(
  q.SelectAll(
    ['name', 0],
    [
      { name: ['Jane', 'Eyre'] },
      { name: ['John', 'Connor'] },
      { name: ['Thomas', 'Magnum'] },
    ],
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 'Jane', 'John', 'Thomas' ]
result = client.query(
  q.select_all(
    ["name", 0],
    [
      {"name": ["Jane", "Eyre"]},
      {"name": ["John", "Connor"]},
      {"name": ["Thomas", "Magnum"]}
    ]
  )
)
print(result)
['Jane', 'John', 'Thomas']
result, err := client.Query(
	f.SelectAll(
		f.Arr{"name", 0},
			f.Arr{
				f.Obj{"name": f.Arr{"Jane", "Eyre"}},
				f.Obj{"name": f.Arr{"John", "Connor"}},
				f.Obj{"name": f.Arr{"Thomas", "Magnum"}}}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[Jane John Thomas]
try
{
    Value result = await client.Query(
        SelectAll(
            Arr("name", 0),
            Arr(
                Obj("name", Arr("Jane", "Eyre")),
                Obj("name", Arr("John", "Connor")),
                Obj("name", Arr("Thomas", "Magnum"))
            )
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(StringV(Jane), StringV(John), StringV(Thomas))
SelectAll(
  ['name', 0],
  [
    { 'name': [ 'Jane', 'Eyre' ] },
    { 'name': [ 'John', 'Connor' ] },
    { 'name': [ 'Thomas', 'Magnum' ] },
  ],
)
[ 'Jane', 'John', 'Thomas' ]
Query metrics:
  •    bytesIn: 148

  •   bytesOut:  37

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 6ms

  •    retries:   0

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!