Selecting multiple fields in an FQL query

Chris Biscardi
InstructorChris Biscardi

Share this video with your friends

Send Tweet
Published 3 years ago
Updated a year ago

You can use array and object literals to compose multiple selections into a single query, such as within a lambda.

Map(
  Paginate(Match(Index("all_customers"))),
  Lambda(
    "X",
    Select(["data", "firstName"], Get(Var("X")))
  )
)

with arrays

Map(
  Paginate(Match(Index("all_customers"))),
  Lambda(
    "X",
    [
      Select(["data", "firstName"], Get(Var("X"))),
      Select(["data", "lastName"], Get(Var("X")))
    ]
  )
)

with objects

Map(
  Paginate(Match(Index("all_customers"))),
  Lambda(
    "X",
    [
      Select(["data", "firstName"], Get(Var("X"))),
      Select(["data", "lastName"], Get(Var("X")))
    ]
  )
)

Map( Paginate(Match(Index("all_customers"))), Lambda( "X", { firstName: Select(["data", "firstName"], Get(Var("X"))), lastName: Select(["data", "lastName"], Get(Var("X"))) } ) )

Instructor: [0:00] Here, we have an FQL query. We match on the index all customers and paginate the results. We map over those paginated results, using a Lambda, and select the first name out. Lambda defines a variable x. We select the first name out of the resulting object.

[0:19] If we run this query, we can see that we do get all of the first names from all of the customers. What if we want their last name, too? First, we'll use an array. We can take our select statement and duplicate it, then replace the field that we want.

[0:44] If we run this query, we can see that we get the first name and last name in an array, which results in a multidimensional array. Typically, we'll probably want to use an object instead.

[1:01] If we use an object when we run our query, we can see that the two select statements have composed to create an object. This pattern of composition is how we'll include multiple expressions to select multiple fields.