I have a users
collection and an invitations
collection. Users can invite multiple users. Records in the invitations
collection document these invites. Each record in invitations
is shaped like this:
"data": {
"sponsor": Ref(Collection("users"), "344418396214919370"),
"sponsee": Ref(Collection("users"), "345390249407414474")
}
The sponsor is the inviter and the sponsee is the invitee. Both reference a user in the users
collection.
I'd like to know the most efficient way in FQL (minimum reads) to get the list of users that a particular user has invited, and some basic information about them.
The indexes I have setup are user_by_email
and sponsee_by_sponsor
. I also have a Function which gets a user by email called (you guessed) getUserByEmail
.
What I have tried so far is:
Paginate(
Match(
Index('sponsee_by_sponsor'),
Call(Fn('getUserByEmail'), 'sponsor@email.com')
),
)
Which gets me what I want but only in user Refs:
data: [
Ref(Collection("users"), "345390249407414474"),
Ref(Collection("users"), "345390805049934027")
]
Above is the result of the query, which are all the users that have been invited by sponsor@email.com
. But they are refs and I would like more information about each of these users, without having to make another read. I'm very new to FQL, so any help would be welcome.
Update
As per a request from the comment, here are the definitions of my indexes and Function:
A typical User document is shaped like this:
{
"ref": Ref(Collection("users"), "344418396214919370"),
"ts": 1665703164070000,
"data": {
"email": "sponsor@email.com",
"name": "Sponsor Name",
}
}
Being able to get the email and name of the sponsees (rather than the Refs) is what is desired in as few reads as possible.