How to query a sync realm without saving its full data locally?


#1

Hi,

I have an app where users need to register to.
once registered each user has its own sync realm (~).
I also have an admin sync realm in which I save the registration data (this is on top of the built in Users in the Realm Studio).
So it turns out that in the admin realm I have a User schema with all the registered users.This can be a very long list.

my question - if in my app I open the sync admin realm (in order to add a record for the user)- does it mean that it will sync all its data to the user device locally?will each user have locally the realm admin full data ?

I suspect that partial sync might be an option - didnt study it yet - but this is quite new and I dont want to relay on this.

Thank you

Yuval


#2

Query-based (Partial) sync was created to solve this problem. I would recommend using it.


#3

@yuvalkro Yes this is exactly what we recommend partial-sync with our query APIs are for:
https://docs.realm.io/platform/using-synced-realms/syncing-data#subscribing-to-data


#4

You should rely on it because it’s what does what you want.


#5

Thank you all.

one more question -

as I stated I have adminRealm which I want regular users to access part of its data.
should I use an admin user to access and subscribe the partial data for each user?
or should I allow all users Read permission on the adminRealm and let them access and subscribe the partial data ?

Thank you


#6

@yuvalkro You would have all users Read permissions and then each user would subscribe only to the data they should have access to which is controlled by client-side app code.

If you wanted to be even more secure you could have a default deny rule on all objects in the realm and then use a backend app with the adminUser which would programmatically apply read object permissions to data that user should have access to as they sign up.