I started to play around with Realm server functions today. What I want to archive is when a new user is created, I want to search all existing realms for a timestamp, and if that timestamp is older than a certain number of days, I'll empty that realm. (I've very new to Node.js!)
1. How to to know when a new user has been created? Can I just look in the
changeEvent if the oldRealm is null or something like that? Or how do I differentiate it compared to modification in an existing realm?
How do I iterate over all realms to find those with an old timestamp? Should I use
Realm.Sync.User.all and loop over those? How do I get their realm from there? And then just call
Is it possible to say when the function should be triggered? Seems a bit overkill to run it each time something is changed in any realm. (And actually, with 2.000 new users per day, I guess that running the function each time a new user is created is also overkill.)
What if they a couple of months later start the app again. Then I don't want their local app to have the data deleted, but that their app with existing data is updating the online realm. How to accomplish that? If I call
deleteAll, then I guess that their local data will get wiped next time they sync.
Thanks for all help! Trying to understand how functions work.