sách gpt4 ăn đã đi

javascript - Firebase 云函数抛出关于 "timestampsInSnapshots"的警告

In lại Tác giả: Walker 123 更新时间:2023-11-30 20:03:43 26 4
mua khóa gpt4 giày nike

当我在云函数中使用 firestore 时,出现以下错误。如何解决这个问题

  error:
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.

câu trả lời hay nhất

解决方案,通过转到 functions 文件夹安装最新的 firebase-functions 和 firebase-admin。


npm 安装 firebase-functions@latest firebase-admin@latest --save

然后在您的云函数中添加如下内容:

const firestore = admin.firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);

关于javascript - Firebase 云函数抛出关于 "timestampsInSnapshots"的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53127086/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress