Sync an object manually created

Hello,

We created a MongoDB document from the MongoDB Atlas interface with the correct partitionValue (userId in our case) but in our mobile app, we can’t retrieve theses documents through our synced Realm.

Then, for testing, we created a document directly from the mobile app with the synced realm, and it worked, the document created was exactly the same as the one created manually (but for the _id key).
When we try to get all the objects from the Realm collection, we only get the one created through realm and not the one created manually.

So our guess is: If we created a document manually, it will not be linked the Realm, event if this database is the same that realm use.

In fact, our need is to populate a lot of datas from our backend so all the users can get them through Realm using a public partition key.

Do you have any ideas to how we can do this ?

Thanks.

Hi Pierre,

We created a MongoDB document from the MongoDB Atlas interface with the correct partitionValue (userId in our case) but in our mobile app, we can’t retrieve theses documents through our synced Realm.

I understand this to mean you inserted a document using the Atlas Data Explorer but you were not able to retrieve this document in your Sync Client (mobile device).

Then, for testing, we created a document directly from the mobile app with the synced realm, and it worked, the document created was exactly the same as the one created manually (but for the _id key).

Here you created a document in the sync client and the document appeared in MongoDB when checking through the Atlas Data Explorer.

When we try to get all the objects from the Realm collection, we only get the one created through realm and not the one created manually.

I’m not sure what you mean by this.
Whether you perform writes on MongoDB or in a Sync Client, the data should get translated in either direction. i.e. creating an object in your mobile should appear in Atlas and create a document in your Atlas collection should appear in your mobile device - if configurations allow for that.

What I’m understanding from your description is that data is not always being synced between MongoDB and your Sync devices. The cause behind this could be numerous and we would need to take a look into your environment to pinpoint what exactly is failing, as such I would recommend that you raise this in a Support Case with us for investigation.

Having said that you could check a few things on your side:

  • Are there any errors in your Realm Logs when performing a write? You can filter this by errors and type “Sync”.
  • Are there any errors in your Client Logs when trying to reproduce the issue? We would recommend enabling .trace Client Log Level to get detailed information about this.
  • In the client are you opening the correct partition associated with the new document inserted in Atlas?
  • Does the user on the client have the correct Sync Permissions to access the document in question?
  • Can you see any documents in the __realm_sync.unsynced_documents collection? The documents in this collection mean that they will not be synced as they were created in a way that does not comply with your cloud schema. When this happens you will also see an error in your Realm logs. To correct these you will have to run a replace() command to bring it into compliance. Note that the __realm_sync database is hidden so it will not appear in Atlas data explorer however you can query it in Compass or MongoShell.
  • Are you able to see the document on a new client? It’s possible a client reset is required on pre-existing clients. See article on Breaking Vs Non-Breaking schema changes.

Hope that helps.

Regards