Realm Sync clarifications

Hi @Desislava_St_Stefanova. I would appreciate some clarification on Synced Realm. My question are:

  1. Is querying synced real from client flutter app would be count as paid read ? As I do understand It would not as realm installed locally.

  2. Is it better to store just ObjectId or Reference with synced Realm?
    late Product product: … => reference
    late ObjectId productId: <some ObjectId(AAA)>

  3. Does synced Realm perform automatic $lookup(s) when I use reference? If yes, does it count as paid read query? E.g.:

CartItem {
 late List<Product>products;

Every time I query CartItem products is accessible.

  1. Does synced Realm support N-N relations ?

Hi @shyshkov.o.a!
We are glad to have your interest on the realm!

Flutter Realm SDK supports Flexible sync, which means that the developer is able to control the data that are downloaded to the client by query filter (subscription) and by user permissions.
I you use flexible sync you have to define subscriptions as it is described in the documentation. Filtering by permissions is an addition option where you can use roles with custom user data.
We create a realm file on the device per user. The data for each user is in different file.
All the realm objects that match the subscriptions and user permissions for the current user are downloaded in background initially or if there is some data changed on the server. If you need to wait for the sync processes to complete you can use the following methods realm.subscriptions.waitForSynchronization(), realm.syncSession.waitForUpload() and realm.syncSession.waitForDownload().

  1. Once the data are on the realm file on the device you can read them fast as many times you need. If you do a change then it will be uploaded to the server automatically. If another device change the data and sync them to the server then the change will be downloaded to the first device if it matches the filters. But these are background processes that will not cause a performance issue while you read/write data.
  2. I would suggest you using references when you define your model instead of using Ids. It is much easier to work directly with objects. If you need the CartItem and the Product you have to define subscriptions for both types.
  3. The data for each property of an object are read from the local file only if you access the property. The implementation of each property of the RealmObject has an accessor that does the reading only of you read the property somewhere in your code.
  4. Yes realm does support N-N. You can have CartItem.products and Product.cartItems. You might be interested of using Backlinks which will help you to fill the collections automatically.

I hope the described will answer your questions!

1 Like

Thanks a lot @Desislava_St_Stefanova. Really appreciate that you replied to me. :slight_smile:

As far as I know SYNCED Realm don’t support BackLinks(Inverse Relationships), and as I do understand N-N as well. Right? Just need to understand is this is the same thing N-N and Inverse Relationships.

Do I have a chance to ask some of MongoDb expert to take a look on my schema design (UML diagram)? I’ve herd that you are helping start-up(s). A bit rude request form my side, just iggore it if it’s not appropriate.

Sync’d Realms operate and work exactly the same as a local only Realm; and ‘backlinks’ operate in the same fashion. You can think of a backlink as a computed property as they are not “stored” in the same way as a forward relationship. When an object has a backlink property, it’s automagically ‘filled in’ when the forward link is created.

Backlinks allow you to traverse the object graph inversely, so they are an inverse relationship.

You can always post coding questions here on the forums or on StackOverflow; keeping in mind that questions about object models (Schema), relationships between objects, what queries will be run etc are really difficult to answer without knowing the entire use case.

Best bet is to crank up your development environment and write some code! Go through the getting started guides and work through the example projects. Then when you get stuck, post a question containing the code you’re stuck on and the troubleshooting.

Welcome to the Realm Forums!


@Jay im a bit confused, docs has this statement:

Yes, that’s correct!

They are not present anywhere! e.g. you can’t actually “see” an inverse relationship or set it’s value whether it be a sync’d or local Realm.

It’s essentially a “computed property”, as mentioned, and that’s done at the device level.

In other words, if there’s a Person and Dog class, and the Person has a one to many relationship with Dog, and Dog has a LinkingObjects (inverse relationship) to Person, of you use the Realm Browser and look at the schema, the Dog object doesn’t actually show the LinkingObjects property back to the person, even though it’s defined on the model.

The key to the note you linked is that if you’re logged into the realm console and look at the Dog object, you will not see the property that provides the inverse relationship as it “doesn’t exist” on the server (either) - it’s computed at the device level, not server.


Thanx @Jay , that is an excellent explanation. Now I finally got it.