We write to the collection defined in the “schemas” tab of the UI. The “database name” here is just where we add any new tables that are added via Development Mode (where we let the Realm SDK define new Schemas automatically in the cloud UI). Let me know if that makes sense.
I actually recently filed a ticket to update the docs with more information on this. The TLDR is
Realm Tables have a singular “table name”
MongoDB Collections have a “database” and a “collection” that defines a unique collection
The “title” field in the json schema determines the “realm table name”
What this means:
You can sync from any table to any “db.coll” and you can define this mapping in the schema page
You can sync with multiple databases
You can sync on multiple collections with the same name in different collections as long as the “title” field is different in the two different schemas
You cannot have two collections with the same “title” field since it would be unclear which one new realm objects should map to
You cannot sync to multiple clusters
The “database name” in the sync config is only relevant to adding new tables in dev mode. Because we just have a “table name” it defines which database new tables should go in and then they are added with a collectionName==tableName
You have multiple “person” collections but realm will sync to whichever one has the “title” of the realm object being synced.
Okay. I’m making progress in understanding! Both collections have the same “title” name and that’s whats causing the confusion.
This introduces a follow up question:
1.How do we do different environments (production, debug)? Was under the impression I could create a new application in the same project? But if that leads to the same Schemas how should we approach it? Different projects?
Hi @Alexandar_Dimcevski – We would typically recommend different applications as well as either different Atlas clusters or databases to support development/testing environments. You can use environments/environment variables to ensure that your applications are pointing to the right resources as you promote code across environments. You can find an overview of our recommendations here.