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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With