Reputation: 301
I am not familiar with javascript but I would like to create a firebase function that will set a negative server timestamp on a ref but I keep getting the same error:
Error: Reference.set failed: First argument contains NaN in property
Here's my code:
exports.makeNegativeTimestamp = functions.database.ref('/items/{itemID}/negative_created_timestamp')
.onCreate((snapshot, context) => {
const timestampCurrent = admin.database.ServerValue.TIMESTAMP;
const now = Date.now().valueOf();
var negativeTimestampCurrent = (now * -1);
return snapshot.ref.set(negativeTimestampCurrent);
});
I tried using both admin.database.ServerValue.TIMESTAMP
to set value and Date.now().valueOf()
but both lead to that same error.
Any help would be greatly appreciated.
Upvotes: 0
Views: 139
Reputation: 598797
ServerValue.TIMESTAMP
is not a value that you can read. It is a so-called marker that you can write operation, which the server then replaces with the actual timestamp when it writes the data to the database.
I'm not sure what Date.now().valueOf()
is meant to do. Aren't you simply looking for Date.now()
, which gives you the current timestamp?
Upvotes: 3