Selecting multiple fields in an FQL query

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years 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.

egghead
egghead
~ 37 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today