using firebase functions (NODE) I would like to create a timestamp base node to save my data using timestamp as key name:
EX:
WATERLEVEL
16934723478:1
16934723482:2
16934723483:50
I'm trying to using this code without success.
const timest = admin.database.ServerValue.TIMESTAMP ;
let waterData = {};
waterData[timest] = req.body.WATERLEVEL;
rtdb.child("SENSOR").child(req.body.SERIAL).child("LEVEL").update(waterData);
Can somebody drive me to the right approach ? could a variable been used as key ?
CodePudding user response:
The admin.database.ServerValue.TIMESTAMP
variable is not actually a timestamp, but an instruction to the database to write the current timestamp. There is no way in the Firebase Realtime Database to write this value into a key; it can only be used in values.
If you want to write the current server-side timestamp from Cloud Functions as a key, use:
const timest = Date.now();