Mongo Data API and CORS

Hello, I’m trying to query my Mongo DB on Atlas through the Data API, from the browser (with an Angular app) but I’m blocked by CORS.
I guess it’s by design and the Data API is supposed to be consumed from server apps, not client apps, as the UI in the admin dashboard doesn’t show anything that makes me think I can configure CORS, but just in case there’s a way around this I’d be glad to hear it.

1 Like

Hey Andrea - you’re correct, currently it’s blocked by CORS because we don’t yet offer additional authentication and authorization options. Feel free to request it on Atlas: Top (800 ideas) – MongoDB Feedback Engine and choose the ‘Data API’ category so we can gauge interest.

Other ways to get around this is to wrap it in a backend or another managed service like Lambda or put an API gateway in front of it.

1 Like

Hi folks,

For anyone who has a similar use case where CORS or a browser-only application environment currently prevents using the Data API (Preview), please watch/upvote the feature request to Support CORS from the Data API (MongoDB Feedback Engine).

This feature request is currently under review, so any additional context on desired use case support would be helpful – start a new forum discussion using the data-api tag.

In the interim, some alternative approaches to consider include:

  • Putting an API gateway or serverless function in front of the Data API calls (as mentioned earlier in this topic).

  • Using the MongoDB Realm GraphQL API:

  • Using the Realm Web SDK.

Regards,
Stennie

2 Likes