Replies: 1 comment
-
You can prevent a loop by providing a context in your update: db.ref('my_collection').on('notify_child_changed', ref => {
const context = ref.context();
if (context && context.lastModifiedEvent) {
return; // Prevent recursive updates
}
// Update last_modified
ref.context({ lastModifiedEvent: true }).update({ last_modified: Date.now() });
}); Also see Get triggering context of events |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
mongodb has a feature where it auto updates a "last_modified" field whenever a record is updated. is there a similar feature here? if not, its there a preferred way to handle this? Getting the current date from the client will be inaccurate. I could watch for mutations on the server and update the record afterwards, but i think that'll cause every modification to trigger 2 update events (or even an infinite loop). I could get the server date before updating, but that could have problems too (if offline or temporarily not connected)
Beta Was this translation helpful? Give feedback.
All reactions