dalenguyen / firestore-import-export

An application that can help you to backup and restore from Cloud Firestore | Firebase
https://www.npmjs.com/package/firestore-export-import
401 stars 109 forks source link

Firestore warning message displays in console #7

Closed 185driver closed 6 years ago

185driver commented 6 years ago

Thank you for the helpful plugin!

Recently, I started getting this warning message when using this plugin:

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 asFirebase 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.

It's due to a recent update of Firestore, and not an issue with the plugin, but it would be nice if the warning message could be suppressed in the console, maybe via a code change of some sort? Thanks for considering.

dalenguyen commented 6 years ago

Hi @185driver, the error with disappear if you add this code to your app. Remember to replace firestore if you change the way you declare firestore.

const firestore = new Firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
185driver commented 6 years ago

Thanks for the heads up. I do already have that code in my apps that use Firestore. In this particular case, I'm seeing it when using export.js by itself with my service-key.json file. Am I missing something?

dalenguyen commented 6 years ago

Hi @185driver, can you take a snapshot of what you are doing and the warning if it is possible?

185driver commented 6 years ago

I fixed it. Both import.js and export.js (lines 14 and 13, respectively) contain const db = admin.firestore(); By adding db.settings({ timestampsInSnapshots: true }); on the next line of both scripts, the Firestore warning message is successfully suppressed.

My suggestion is to add db.settings({ timestampsInSnapshots: true }); to both of your example scripts so as to better support the more recent versions of Firestore.

Again, thanks for this helpful plugin.

dalenguyen commented 6 years ago

Thanks, @185driver, you're right. It depends on how we initiated the firebase app. I will update the scripts.