Delete realm files + resync again realm swift sdk

Hello team,

we are deleting realm files(3 partition so generated 3 realm files) and resync(craeting realm files) again. files are not generating again but data showing without realm file.

Thanks in advance

If you’re saying that after deleting your local Realm files, you can still access that data, that’s correct!

Realm has some ‘hidden’ cache files that contain data and as long as there’s a reference to the Realm in your app that’s still active, those files will still contain data.

To fix this you have to ensure that Realm has no references to it before deleting the files. And I really mean NO references. Even a let realm = Realm() creates a reference.

So what we do is to ensure all vars go out of scope and set everything to nil before deleting the files - including viewController class level notifications.

Thanks for the reply.

But can you please tell me how can we re-generate realm files without app relaunch??

Thanks in advance.

I believe that since you have completely disconnected from Realm and nil’d all references to delete the files, if you reconnect via the normal .async method,

Realm.asyncOpen(configuration: configuration) { (result) in

it will re-sync all of the data without having to restart the app.

I have not tried it but am going to shortly.

Hello Vishal,

Do you by chance have working Client Reset Logic implemented?

@Brock_GL I am not sure the OP has that situation. The client reset override is really to handle server errors & crashes (generally); for example in the case of when the data on the client is newer than what’s on the server due to a server crash. Another example is when the server has instructed the SDK to reset, which then deletes the local data. The override can then recover lost data from the local backup to the newly created Realms. The key is its best use is when the server data is older than the client data.

I believe OP has the opposite situation where they’ve intentionally removed the local data and only want the data to be pulled from the server and not recovered or handled from client data.

Thinking through it, the end result may be the same.

@Vishal_Deshai I can confirm, that while the app is running if all of the references to Realm are removed/released and then all of the local Realm files are deleted if the Realm.asyncOpen(configuration: connection method is called, all of the data will pull down from the server and new local Realm files will be created.

1 Like

HI @Brock_GL ,

As per my implementation, real files will be generated when App instance created and App is singleton class so initialised only once.

Please have a look

Client File Identifier

into below link: https://docs.mongodb.com/realm/sync/learn/protocol/

Thanks in advance.

Hello Vishal,

I am familiar with the Client File Identifier, but I do have a question.

Could you go into Atlas, click the Realm Tab, then on the left hand side in the vertical selection bar could you click on “Logs” and then click filter by type and select “Errors” and then click “Search”?

This will then show you the error messages associated to your Realm.

Let me know if any errors are visible?

Regards,

Brock