🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 06 : 07 : 54
1×
Become a member
to unlock all features
Autoplay

    Accessing fields through Refs with Select

    Chris BiscardiChris Biscardi
    faunadbFaunaDB

    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"))))
    )
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.