Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a date to Firebase Firestore Node.js

I can't seem to find anywhere in the Web/Javascript docs anything about saving Dates to the Firestore. In Swift, I create a variable using NSDate and then Firebase is able to store that as a date object in the database. Is there similar functionality in Node.js? Can I use the date-and-time package or is there native support for Dates in Node.js?

like image 939
Matt Bart Avatar asked Sep 23 '26 01:09

Matt Bart


1 Answers

From the Firestore documentation on saving data of supported types:

var docData = {
    stringExample: "Hello world!",
    booleanExample: true,
    numberExample: 3.14159265,
    dateExample: admin.firestore.Timestamp.fromDate(new Date("December 10, 1815")),
    arrayExample: [5, true, "hello"],
    nullExample: null,
    objectExample: {
        a: 5,
        b: {
            nested: "foo"
        }
    }
};
db.collection("data").doc("one").set(docData).then(function() {
    console.log("Document successfully written!");
});
like image 155
Frank van Puffelen Avatar answered Sep 26 '26 00:09

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!