SelectAll

SelectAll( path, from )
SelectAll( path, from )
SelectAll( path, from )
SelectAll( path, from )
select_all( 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

The path to the field in the document to extract

from

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:

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))
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]
System.out.println(
    client.query(
        SelectAll(
            Arr(Value("people"), Value("name")),
            Obj(
                "people",
                Arr(
                    Obj("name", Value("Jane")),
                    Obj("name", Value("John")),
                    Obj("name", Value("Thomas"))
                )
            )
        )
    ).get());
["Jane", "John", "Thomas"]
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']
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:

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))
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]
System.out.println(
    client.query(
        SelectAll(
            Arr(Value("name"), Value(0)),
            Arr(
                Obj("name", Arr(Value("Jane"), Value("Eyre"))),
                Obj("name", Arr(Value("John"), Value("Connor"))),
                Obj("name", Arr(Value("Thomas"), Value("Magnum")))
            )
        )
    ).get());
["Jane", "John", "Thomas"]
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']
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!