Jitendra Tiwari
Jitendra Tiwari

Reputation: 1691

firebase.database() Date is not submitted

I have tried to create a record in the firebase real-time database from an AngularJS web application.

Code

firebase.database().ref("XYZ").push({
      name: 'name',
      contentType: 'video/mp4',
      videoUrl:downloadURL,
      createdDate: new Date(),
      uploadedBy: '[email protected]'
})

Problem

Record created successfully but createdDate field will not added in database. what is the issue?

Upvotes: 10

Views: 9651

Answers (1)

Devid Farinelli
Devid Farinelli

Reputation: 7544

It doesn't work because you are trying to push a Date object instead of a timestamp/string. You should use:

  • Date() to get a string like: Thu Jun 30 2016 09:40:54 GMT+0200 (CEST)
  • new Date().getTime() or Date.now() to get a timestamp like 461467272336700

If you are looking for a nicer solution you should let Firebase set that value with its current date using firebase.database.ServerValue.TIMESTAMP

Upvotes: 28

Related Questions