Need help targeting different databases and defining MongoDB database name in Realm Flutter SDK

Hey everyone,

I’m currently working on a Flutter project and utilizing Realm SDK for database operations. However, I’m encountering some challenges regarding targeting different databases and defining MongoDB database names within the Realm Flutter SDK.

Specifically, I’m unsure about how to specify different databases within my Flutter application and how to set the MongoDB database name. I’ve looked through the documentation, but I couldn’t find a clear explanation on how to achieve this.

realm = Realm(Configuration.flexibleSync(currentUser!, [Item.schema]));

Thanks in advance!

The client-side SDK doesn’t have a concept of MongoDB database name - you can define it in the Data Access/Schema tab in the web UI. There you’ll see a list of all databases on your cluster and have the option to define a schema for each collection. One thing to note is that the title of your schema definitions should be unique across your application, so if you have collections with identical names across different databases, you’ll need to give them a different title.

1 Like

Is it mandatory to define databases and schemas in the web UI?

Hi, I would reccomend reading this page in the docs about this: https://www.mongodb.com/docs/atlas/app-services/sync/data-model/data-model-map/

Given that Realm has no concept of namespace being two disjoint things (database.collection), custom mappings must be defined in the backend. You can utilize the UI, Admin API, CLI, or Github Auto-Deploy in order to do that.

Best,
Tyler

1 Like