Accessing fields through Refs with Select

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

Refs are opaque. To access the fields on a document associated with a Ref, we first need to run Get on our results and then we can access fields using Select

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

Instructor: [00:00] Here we have a query where we paginate on the match of all the documents in the index, all customers. We map over the resulting page set and get each of the refs. Let's say we don't want all the results, because it's quite long and we don't need to return them. Let's say the only field we need is the firstName. We can use Select for this purpose.

[00:24] In our Lambda, we'll add a call to Select. Note that we use the value of Get as the argument that we're operating on. To select through data into the firstName, we can use data and then firstName, because the result of Get is a single object and not the full result list. After running this, we can see that we've selected the first name from each of the documents.

egghead
egghead
~ 16 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