Migrating from Legacy Realm Sync to MongoDB Realm Guide

@Ian_Ward - I have raised a support ticket with details of the MongoDB Realm appID and scripts that were used to load the data - It might be easier for you guys to look at the scripts and logs yourselves as there are multiple errors that don’t mean much to me.

Just a followup - it seems that if I add a delay between each write to the synced realm the data gets synced correctly. Initially I had a 1 second delay but seemed to get a bunch of errors and data never seemed to show up in Atlas, and then some data showed up but not other data.

Anyway I bumped the delay to 10 seconds and now all the data seems to have loaded successfully even though there appear to be a bunch of errors in the logs. It’s not really clear if these errors are indication of fatal sync errors or not. In any event it seems the correct number of records exist in the synced realm and if I create a new client and connect to the same Realm App the data that gets synced to the client also contains the correct number of records.

That’s a good start but relying on a client delay between writes to the realm for successful sync of newly created records is a rather fragile approach - if this is indeed the reason why data as not being synced originally.

I will try a few more tests since it is possible I had done something wrong when setting up Atlas/MongoDB Realm during my initial attempts.

FYI I am just deleting the Realm App and then the Atlas database and recreating them, setting them to Dev Mode and then running the client load script. It seems I have to keep the javascript client application running for some time after the copy process completes to allow the sync to complete - I am not that familiar with the javascript APIs but perhaps some way to check when any sync is completed would be a more elegant solution that simply waiting on console input to prevent the javascript application from ending.

I have checked the migration guide and have made changes accordingly on the app side code.
Old data is populated in atlas.
User will not be having his auth credentials in realm, how to handle them?
User data is migrated and is present in the atlas db.
When old user tries to login it will fail, because that user in not present in sync.
Forecefully register that user in auth, and call login again ?
Apart from this any other thing which i should be aware of ?

@spam_mail There is an admin API available on Realm Cloud which enables to programmatically create User accounts - https://docs.mongodb.com/realm/admin/api/v3/#users-apis
For this thought, you would need the user’s password… which I hope you do not have! :smiley:

If the there is user specific data, data that only certain user’s should have access to, then you will need to set up permissions. One way to do this is to create a collection in Atlas that has a mapping of users to the data they have access to. Users to the new Realm Cloud will need to re-register and when they do you could use an Auth trigger to set the permissions -

The trigger fires when a new user registers, it performs a lookup on the collection where you have a mapping of users to permissions, and sets the user’s custom user data - https://docs.mongodb.com/realm/users/enable-custom-user-data/
The custom user data is what contains information on what partitions that user has access to on MongoDB Realm and is pulled from legacy Realm Cloud and stored in Atlas.

Of course the above is for when you had user-specific permissions, if not, then your re-registration flow can be a lot easier.

Hope this helps


1 Like

Hi Ian,

Still stuck in the conversion step.
You wrote “A List property would be an array of these _ids” - so I converted my data to be as such and now lists are represented as array of strings, but it raise an error because in the realm scheme it still defined as a list of another table (schema).

  1. should I change the realm scheme to be an array of strings instead of a list ?
  2. if the answer to 1 is yes - do I need to change my code and now add another query in my code to fetch the record of these id’s from the connected table when needed? because until now I could simply access them via the main table object (e.g. User.userDevcies[0].DeviceType

this is an example of my realm User schema with a list property (userDevices ):
User.schema = {


primaryKey: '_id',

properties: {

    _id: {type: 'objectId',optional:false},
    _partition:  {type: 'string',optional:false},
    id                : 'string',    
    userID            : {type: 'string'},
    registrationDate  : {type: 'date'},
    userDevices       : {type:'UserDeviceInfo[]'},


Thank you


No - you should still use a list of Relationships in your schema but the new Realm Sync will store that data as an array of strings in the MongoDB document. This is because there is no concept of relationships in MongoDB so this is what we landed on. For your schema, but on the Realm Client and the Realm Server - the field will still be a List of Objects.

Hi Ian,

Just to make sure im not confusing -
I have realm scheme which is in my code, and the Realm Sync schema which is defined in the MongoDB.
In the Ralm schema I keep the List and in the matching schema on the Realm Sync I set the same property as an array of strings as in the below example?

“userDevices”: {
“bsonType”: “array”,
“items”: {
“bsonType”: “string”

If I do that I get an error that the schemas are not matching :

The following changes cannot be made in additive-only schema mode:

  • Property ‘User.userDevices’ has been changed from ‘array< string >’ to ‘array< UserDeviceInfo >’.