firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK

Open itaydressler opened this issue 8 years ago • 6 comments

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Firebase cloud functions (node 6).
  • Firebase SDK version:
  • Library version: 5.12.1
  • Firebase Product: firestore

[REQUIRED] Step 3: Describe the problem

Getting errors when initializing the firestore() module. Not sure what is the correct way to pass the settings objects when using firestore with the admin library.

On the client side I can just use firebase.firestore().settings({ timestampsInSnapshots: true });, but I can't find the correct way to do the same thing with the admin package. The suggested fixing method in the error log does not seem to relate to using firestore with the admin package.

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 = new 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. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:

  // Old:
  const date = snapshot.get('created_at');
  // New:
  const timestamp = snapshot.get('created_at');
  const date = timestamp.toDate();

Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.

Steps to reproduce:

Initialize admin.firestre() in a cloud function.

itaydressler avatar Aug 06 '18 08:08 itaydressler

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Aug 06 '18 08:08 google-oss-bot

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Aug 06 '18 08:08 google-oss-bot

Got it to work after updating to the latest version.

itaydressler avatar Aug 06 '18 11:08 itaydressler

I still have this issue too, even after updating

exit99 avatar Sep 10 '18 23:09 exit99

Its whenever you request a firestore document that has a timestamp value. This value is created on the document through the web portal

exit99 avatar Sep 10 '18 23:09 exit99

Still have this issue with "firebase-admin": "^6.5.1"

GaetanRouzies avatar Feb 14 '19 12:02 GaetanRouzies