MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Realm instances

I pretend to integrate Realm on my react-native app. By the moment, I have established two Schemes (bookingsScheme and ubicationScheme). The problem is that I want to read the information contained in the schemes in multiple screens and for doing that I open a Realm instance for each screen, but when I do that shows up an error saying that: ‘Realm at path X already opened on current thread with different schema.’.

I understand the error, and I try to find the solution. I put realm.close() each time I create a Realm instance, but when I do that another error jumps saying that Realm has been closed and the data is invalidad.

I suppose that I don’t understand how Realm exactly works, and I’m wondering what I should to do at time of create instance of Realm.

My idea is having the app data structure handled by Realm. I have thought pass a unique Realm instance with Redux but I don’t think that it was a good solution.

@David_Arnau You can open the same realm with both schemas and then use two different filters to just get bookings and ubication objects to bind to separate views - see here:
https://docs.mongodb.com/realm/react-native/reads/#filter-results