Query-based Synchronization with Created Time


On default, I want to load the newly created objects (ex: objects created in the last 10 days only). And then, give the user to load older objects when needed or by searching.

I created an async query to load the new objects and it works. But it keeps the objects which does not match the query (ex: objects older than 10 days are not removed). This will make the database to grow with objects we do not need more often.

How can I get rid of these old objects while keeping them in the Cloud and loading back only if needed.

In general, how can I keep only the objects which are queried frequently and remove other objects till they were queried again?


You can provide a name when creating the subscription and then unsubscribe when you don’t need it anymore. That way old objects will be removed from your device.

You can read more about subscribing and unsubscribing here: https://docs.realm.io/platform/using-synced-realms/syncing-data#using-query-based-synchronization


Yes, then I have to unsubscribe from that data set before exiting the app or at some meaningful time. But then no data will be available when I run the app next time, am I right?