Firebase Cloud Functions Is Deleting Nodes Instantly Instead Of Deleting After 2 Hours
I'm using Cloud Functions to delete nodes after 2 hours on firebase.However, when I add a node, it is being deleted as soon as it is created inside the database My index.js: const
Solution 1:
Your timestamps are stored in seconds, not in milliseconds. Since your code uses Date.now
, which returns the timestamp in milliseconds, you're comparing values that are 1000x off.
The simplest solution is to:
const CUT_OFF_TIME = 2 * 60 * 60; // 2 Hours in seconds
Solution 2:
You are comparing timestamp in milliseconds with timestamp in seconds.
var cutoff = now - CUT_OFF_TIME;
- The cutoff value is in milliseconds
You need to change the CUT_OFF_TIME
and convert Date.now()
to seconds.
Post a Comment for "Firebase Cloud Functions Is Deleting Nodes Instantly Instead Of Deleting After 2 Hours"