Hi,
My goal is to display relevant user information from different collections based on their IDs (employeeId or employerId). I would like to show a list of those connected users and get the data from the specific documents.
If you as a user have the role “employer” you will save all your information in a document within the “employer” collection. The same goes for “employees” if you have the role “employee” your data will be stored within the “employee” collection.
I then have a collection called “connections” with documents created in the moment an employer and an employee decide to connect with each other. A document from that collection looks like this:
{
"ref": Ref(Collection("connections"), "336420921043583169"),
"ts": 1657094868435000,
"data": {
"employerId": "330616765804445892",
"employeeId": "330616700633350340",
"isEmployeeApproved": true,
"isEmployerApproved": true,
"connectionAcceptedOnDate": "2022-07-06T08:07:47.846Z"
}
}
You will notice that we have employerId
and employeeId
. I would like to show the specific document from the other collections if they contain the specific IDs.
I’ve tried using Join
but it seems that I have to provide the employerId
or employeeId
as an argument before I can join with another collection. Below is what I tried:
const getConnections = async () => {
return await faunaClient.query(
q.Map(
q.Paginate(
q.Join(
q.Match(
q.Index("connections"),
employerId,
employerId,
),
q.Lambda(
"employerId",
q.Match(q.Index("employers"), q.Var("employerId"))
),
q.Lambda(
"employeeId",
q.Match(q.Index("employees"), q.Var("employees"))
)
)
),
q.Lambda("ref", q.Get(q.Var("ref")))
)
)
}
Here is the connection index I’m using:
Source collection:
connections
terms:
- data.employerId
- data. employeeId
Here is the employers index I’m using:
Source collection:
employers
terms:
- data.employerId
Here is the employee index I’m using:
Source collection:
employees
terms:
- data. employeeId
How can I get the documents from the collections employers
and employees
based on the IDs from the connections
collection?