21
votes

Because of the warning about the upcoming change in timestamp behavior in Firestore, I am trying to change the initialisation code for my app.

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:

const firestore = firebase.firestore(); const settings = {/ your settings... / timestampsInSnapshots: true}; firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects.

I can't find any reference to firestore "settings" though. Would something like this work? The Typescript definition says no...

import * as admin from "firebase-admin";

export const adminApp = admin.initializeApp();

const firestore = admin.firestore(adminApp);
firestore.settings({ timestampsInSnapshots: true });
1
"Timestamp doesn’t exist yet in the admin SDK. They’re working on it." ~ @codingdoug (on Firebase Slack)FrankkieNL
Then why does the warning show up?DarkNeuron
The warning showed up because I was also using the client library in my backend code. And in general I think if you see this warning in a front-end/client application you would expect this to be relevant for the backend as well.Thijs Koerselman

1 Answers

33
votes

I've upgraded the firebase-admin to 5.13.0 and with the following node.js code in my index.js after initializeApp(), that warning went away and my code runs correctly afterwards.

admin.initializeApp();
const settings = {/* your settings... */ timestampsInSnapshots: true};
admin.firestore().settings(settings);