Select

Select( path, from, param_object )
Select( path, from, param_object )
Select( path, from, param_object )
Select( path, from, param_object )
select( path, from, param_object )
select  path, from, param_object
Select( path, from, param_object )
Select( path, from, param_object )

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

path

Long or String

The path to a field in the document to extract.

from

Object

The object containing the data to be extracted.

default

Object

Optional - The value to be returned if the path does not exist.

Returns

The value at the path.

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".

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "select": [ "favorites", "foods", 1 ],
          "from": {
            "object": {
              "favorites": {
                "object": { "foods": [ "crunchings", "munchings", "lunchings" ] }
              }
            }
          }
        }'
client.Query(
  Select(
    Arr("favorites", "foods", 1),
    Obj(
      "favorites", Obj("foods", Arr("crunchings", "munchings", "lunchings"))
    )));
System.out.println(
    client.query(
      Select(
        Arr(Value("favorites"), Value("foods"), Value(1)),
        Obj(
           "favorites", Obj(
             "foods", Arr(
              Value("crunchings"),
              Value("munchings"),
              Value("lunchings")
            )
          )
        )
      )
    )
.get());
result, _ := client.Query(
    f.Select(
        f.Arr{"favorites", "foods", 1},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

fmt.Println(result)
client.query(
  Select(
    Arr("favorites", "foods", 1),
    Obj(
      "favorites" -> Obj("foods" -> Arr("crunchings", "munchings", "lunchings"))
    )))
client.query(
  q.select(
    ["favorites", "foods", 1],
    {
      "favorites": {"foods": ["crunchings", "munchings", "lunchings"]}
    }
  ))
$client.query do
  select ['favorites', 'foods', 1],
         favorites: { foods: ['crunchings', 'munchings', 'lunchings'] }
end
client.query(
    Select(
        path: "favorites", "foods", 1,
        from: Obj(
            "favorites" => Obj(
                "foods" => Arr("crunchings", "munchings", "lunchings")
            )
        )
    )
)
client.query(
  q.Select(
    ["favorites", "foods", 1],
    { favorites: { foods: ["crunchings", "munchings", "lunchings"] } }))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{ "resource": "munchings" }
"munchings"
"munchings"
munchings
"munchings"
"munchings"
"munchings"
"munchings"
munchings

In the example below select extracts the "id" attributes from the Ref.

curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "select": [ "id" ], "from": { "database": "prydain" } }'
client.Query(Select(Arr("id"), Database("prydain")));
System.out.println(
      client.query(
         Select(Arr(Value("id")), Database(Value("prydain"))))
      .get());
result, _ := client.Query(f.Select(f.Arr{"id"}, f.Database("prydain")))

fmt.Println(result)
client.query(Select(Arr("id"), Database("prydain")))
client.query(q.select(["id"], q.database("prydain")))
$client.query do
  select ['id'], database('prydain')
end
client.query(Select(path: "id", from: Database("prydain")))
client.query(q.Select(["id"], q.Database("prydain")))
  .then((ret) => console.log(ret))
HTTP/1.1 200 OK
{ "resource": "prydain" }
"prydain"
"prydain"
prydain
"prydain"
"prydain"
"prydain"
"prydain"
prydain