Hi jkeane!
You didn’t supply the query that you are already running, but I’m guessing it looks something like this:
Paginate(Match(Index("invites_by_sent"), false))
To substitute the reference with the referenced document, you would need to expand your query like so:
Map(
Paginate(Match(Index("invites_by_sent"), false)),
Lambda(
"invite_ref",
Let(
{
invite_doc: Get(Var("invite_ref")), // fetch the full invite document
league_ref: Select(["data", "league"], Var("invite_doc")), // get the league ref
league_doc: Get(Var("league_ref")), // fetch the full league document
},
// compose the return value for this entry in the result set
{
ref: Var("invite_ref"),
ts: Select(["ts"], Var("invite_doc")),
data: {
league: Var("league_doc"),
expiry: Select(["data", "expiry"], Var("invite_doc")),
email: Select(["data", "email"], Var("invite_doc")),
sent: Select(["data", "sent"], Var("invite_doc")),
accepted: Select(["data", "accepted"], Var("invite_doc")),
}
}
)
)
)
This example works by using Map
to iterate over all of the entries in the result set from the Paginate
call. Map
calls the supplied Lambda
function for each result set entry.
Inside the Lambda
, Let
is used to first gather some working values, namely the full invite document, the league
field value, and the full league document from the league
reference.
The second parameter to Let
is the object we want to return for the current result set item: a new object that mirrors the structure of the invite document, but we use the fetched league_doc
value instead of the reference.
Unfortunately, the Merge
function doesn’t help us here because it doesn’t merge objects recursively, so we have to mimic the document field by field.
If the league
document has a ref that you want to include in the result, then you’d revise the Let
definition to fetch that document too, and then make the same kind of mirrored object for the league document.