Using :
Node js sdk
electron app
Vue js(renderer)
I have an app in which initially I want to sync data from server to local instance and for that I’m opening realm asynchronously and I’m closing it when done with the syncing (shall I close this ? as I want to react to the collection changes as well).
realm = await Realm.open(config)
Then after the syncing is done I’m quering in my app for some data which I have synced
by opening my realm synchronously (as user can go offline now) by using:
realm = new Realm(config)
my config object
config = {
schema,
path: getDBPath(),
sync: {
user: app.currentUser,
partitionValue: new ObjectID(getCatalogId()),
error: (error) => {
console.log(error.name, error.message)
}
}
}
What is the best practice to close the realm and when?
The first time a user logs on to your realm app, you should open the realm asynchronously to sync data from the server to the device. After that initial connection, you can open a realm synchronously to ensure the app works in an offline state. Docs link
So I 'm following the same approach but when opening the same config object with two different methods to open the realm I’m getting the error that "same instance is opened on the current thread " which is solved by closing the instance.
But I want to react to changes in the collection if any how can i do that?