Syncing to the wrong DB

The strangest thing is happening. I want to CRUD to the debug database when using realm for my app but it writes to another database named testing

Tried this

  1. Deleting the app, on a simulator and a physical device. Same result.
  2. I verified that I use the correct app id.
  3. I restarted Sync…

What is going on here?

1 Like

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.


Almost. I was under the impression it should land under debug>Person not testing>Person.

Does it have to do with new. So if I change device sync database name it will keep the old one if there are collections there?

Screenshot 2023-01-11 at 6.02.34 PM

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:

  1. You can sync from any table to any “db.coll” and you can define this mapping in the schema page
  2. You can sync with multiple databases
  3. 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
  4. You cannot have two collections with the same “title” field since it would be unclear which one new realm objects should map to
  5. You cannot sync to multiple clusters
  6. 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?

1 Like

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.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.