Realm - Date based storage of certain collections in partitions

Hello guys,

Our application is using realm with the partition based sync strategy.
We are in the middle of defining/changing the partition strategy of our realm application. The application database is more or less not growing in size on most of the collections, but some collections, for example the collection named “documents”, is growing rapidly. In our case, we only need the last 3 months of the “documents” in each partition and want to keep the older ones in our database. Therefore, we are searching for a strategy which allows us to only store a (date-)range of certain collections in the realm partition. Or in other words we want to keep all data of most of the collections but clip the tail on certain collections if the collection-documents do not lie the date-range condition we define.

We hope that there is a way without the need of enforcing us to manage 2 realm apps. We hope that we can solve this with 1 realm sync application.

Furthermore, we also thought about the new Flexible sync strategy, but we want to go into production in the near future and the docs clearly state, that flexible sync is still in preview mode and should not be used in production code.

Hope you guys know a way to help us out here, seems a little tricky …

@Sami_Karak You could use a scheduled trigger to scan for documents older than a certain date and move them out of the collection -

While Flexible Sync is in preview, it is the future of Realm Sync and we plan to go GA later this year so if you are building a new app I’d probably advise you to start with Flexible Sync. Feel free to reach out at if you have additional questions on this.

@Ian_Ward thank you for the fast reply. So by scheduled trigger, you mean to move the older ones out into a new collection? Since we are using aggregations for collection statistics for the customers, having 2 collections for the aggregations of the statistics would be too complicated to handle/preserve. Therefore, we should aim to go for the flexible sync strategy.

Since you recommend using flexible sync on new projects, are there any customers using this in production already?

Thank you

You can use a flexible sync query with a timestamp to perform this filtering before you. But if you don’t need the data in the sync state then it might make more sense to offload that data into warm/cold storage for analytics later.

We have users that looking to migrate their production apps to flexible sync right now

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.