Tuesday 30 May 2017

How to get current timestamp as the key in Firebase

So i have been working with Firebase for a few days now for my IOT project and i need to send a value to Firebase using NodeJS server but the key of that value should not be the auto generated unique code but the current datetime.

  function sendDatabase(dbName, payload1) {

      db.ref(dbName).push(payload1)

    } 

This is the code i have tried, but it creates a unique key ( according to documentation it is a mix of current date time and something else ) which is not what i want.

I want to store it in the database in the following way

dbName
 - 31-05-10-30 : 00
 - 31-05-11-00 : 01
 - 31-05-11-30 : 02
 - 31-05-12-30 : ...

As shown above, i want the current datetime as the key and the payload1 as the value. I have searched Google + Firebase documentation but i could not find a proper solution to this.

I am a beginner to Firebase and help with this would be much appreciated.



via Vihanga Bandara

No comments:

Post a Comment