Multiple Data API App instances for different app flavours


I’m having issues configuring the Atlas Data API. Hoping to get some advice on how to set it up correctly with 3 different app flavours.

I have a mobile app I’m developing at the moment that have the following setup:

  • Device Sync is enabled for end-user private data (using flexible sync where the queryable field is ownerId
  • Atlas Data API is used for all other end-user data (for example user can share a post which is a shared data accessible by others who have permission to do so)
  • Utilises App Services authentication and rules to authorise access to user data
  • There needs to be 3 flavours of the environment (Development, Staging, and Production)

How I set up the 3 environments previously:

I have 3 atlas service apps that are configured with different environment in a single project. Each atlas app has a device sync linked to its own cluster. I also have a data api app that uses an API key which has super access to all data. So far so good. Or so I thought.

The problem:

I come to realise that I need to secure the Atlas Data API access using app service authentication. But because Atlas Data API is a separate instance to the 3 apps that I have, the authenticated users are not the same as the 3 apps I’ve set up.

Current workaround/solution:

I’ve created 3 projects, each with a Data API app enabled with its own authentication service. I enabled device sync for this data api app. When the user logs in using the Realm SDK on the client mobile app, I use its bearer token to secure access to the Atlas Data PI.

So essentially, I have 3 projects that each have a single cluster with a single data api app to circumvent the limit on single data api per project.

However, I miss having the 3 apps in a single project and using the environment feature provided by Atlas App Services.

I’m questioning how the Data API can be used with the environment feature of Atlas App Services? Because it doesn’t work when authentication is required.

Am I doing this correctly? What are some expert opinions on this please?

Any help or advice would be much appreciated!

Thank you.

I solved this problem. Data API does support multiple instances. I just assumed it didn’t because the initial set up was done through the Data API quick link which generated a default data api app.

After reading through the documentation thoroughly, it seems that it is possible by enabling the Data API manually in each app without first going through the Data API quick link:

  1. Click HTTPS Endpoints in the left navigation menu and then select the Data API tab.
  2. Enable the Data API for your app. This generates endpoints that can access any MongoDB data source linked to your app.
  3. Choose an authentication method and enable authentication providers.
  4. Choose a response type.
  5. Save the Data API configuration.
  6. Configure access permissions by defining rules for collections in your linked data sources to allow requests to securely read and write data.
  7. Save and deploy your app.