Filter collections by user collection attribute

Hi everyone,

I am currently exploring the features offered by MongoDB services, in ‘App Services.’ My goal is to understand how these services can be used to meet various needs.

In the context of my experiments, I am facing a specific case: I want to extract specific values from my data collections based on a custom attribute associated with users who authenticate via an access token.

Specifically, I have multiple data collections that contain an attribute called ‘country,’ and I want users who query my GraphQL service to retrieve only items from these collections that match their own ‘country’ attribute.

To achieve this, I also have a collection called ‘users,’ where each user has an array of ‘country’ like that :

countries: [
"FR",
"BE"
]

Example of Shop collection :

{
  _id: "54hdfoi4s6g48shrezhqs",
  name: "Shopy1",
  country: "BE",
}

{
  _id: "5464d4qs44q4s6g48sq4g6qs",
  name: "Shopy2",
  country: "DE",
}

To accomplish this, I have considered using ‘Filter Incoming Queries’ rules to filter data upstream when queries are executed. I have successfully implemented this filtering, but is static: I am unable to capture or pass dynamic parameters when executing a query from Postman or a Node.js application.

If you have any suggestions or ideas to solve this issue and make filtering dynamic based on the user, I would be delighted to hear them.

Thank you!