I'm trying to keep docs synced with a local database for an offline capable app. It would greatly simplify things if I could do myDB.updateDocument(myDoc) and the doc is only updated if it is newer than the one currently in the collection.
I've tried a couple of things and my best guess is that I need to write a cloud function that takes a doc as a parameter, gets the doc (with the same id) from the collection, and compares a date attribute.
Is this a sensible way of doing it? Any better ways or best practices I should know about? Any help would be greatly appreciated.
The way you've suggested seems like the best way to my opinion to tackle this can of action.
The benefit of using it through a cloud function is that in the future you can easily add logical Middleware in the process
Thanks for your quick reply. It's good to know I'm on the right track.
adding the timestamp locally should be a better option?
Sure you have them both in the updatedat field
Recommended threads
- Function executions not getting logged b...
Hello, I have just upgraded on a self-hosted 1.8.1 to 1.9.0 and I have a strange bug where my functions are no longer showing executions in the console, howeve...
- Relationship data Not showing on update ...
Version : 1.9.0 OS/System : Windows10/Docker Database : MongoDB Clean Zero Installation The first thing I did in the testing process was create a category and...
- Cloud Function Deployment Issue – Timeou...
Impossible to deploy a function for more than an hour. My project ID is: 69cc7a82000b42b8f5e2 Here's the error I get after waiting 15 minutes: Synchronous funct...