Firebase更新错误:Firestore中存储的日期对象的行为将更改,您的应用可能会中断

时间:2018-07-23 13:12:30

标签: react-native google-cloud-firestore

我在Firestore 5.2.0中使用react-native,但错误与将Firestore更新到5.0.4有关。

错误是:

Firestore中存储的日期对象的行为将改变,您的应用可能会中断。要隐藏此警告并确保您的应用不会中断,您需要在调用其他Cloud Firestore方法之前向您的应用添加以下代码:

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

任何人都可以帮我解决这个错误吗?

谢谢

Firebase error

2 个答案:

答案 0 :(得分:5)

firebase.initializeApp({
  apiKey: "AIzaSyCPW020BADuNGvwOPhad4XSq_UYVK3OSxM",
  authDomain: "firestorecrud-b08be.firebaseapp.com",
  databaseURL: "https://firestorecrud-b08be.firebaseio.com",
  projectId: "firestorecrud-b08be",
  storageBucket: "firestorecrud-b08be.appspot.com",
  messagingSenderId: "742054197796"
});

const settings = {timestampsInSnapshots: true};

firebase.firestore().settings(settings);

只需在配置Firebase / firestore代码的代码中添加以上两条语句即可。

答案 1 :(得分:0)

截至2019年3月的更新

对于5.8.0或更高版本

您不应再收到此错误。

Version 5.8.0 - Jan 17, 2019中引入了一些重大更改:

  

BREAKING :现在默认启用timestampsInSnapshots设置。现在,将从DocumentSnapshot读取的时间戳字段将作为Timestamp对象而不是Date返回。任何期望接收Date对象的代码都必须更新。

注意:如the official docs中所述,timestampsInSnapshots将在以后的版本中删除,因此请确保将其完全删除。

对于较早的版本(5.7.2及更低版本)

这应该可以完成工作:

firebase.firestore().settings({ timestampsInSnapshots: true });