javascript - Firebase 云函数引发有关“timestampsInSnapshots”的警告
问题描述
当我在云函数中使用 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.
解决方案
解决方案,通过转到functions
文件夹安装最新的 firebase-functions 和 firebase-admin。
npm install firebase-functions@latest firebase-admin@latest --save
然后在您的云功能中添加如下内容:
const firestore = admin.firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
推荐阅读
- c# - HoloLens 无法连接到 OpcUa 服务器
- c# - 有没有办法在 ConfigureServices 方法中添加 DbContext 服务的连接字符串后在 Configure 方法中更改它?
- flutter - 如何在 Flutter 中使用 SharedPreferences 保存 DateFormat?
- powershell - Powershell 自动服务重启
- javascript - DATABASE_ERR 是如何发生的?
- python - 以不可编辑模式从 bitbucket 安装 python 包
- module - 为什么在尝试通过 DXL 编辑模块时,DOORS 模块有时会为空?
- c# - 如何将 HttpClientFactory 与 AutoRest 生成的客户端一起使用
- vb6 - 将 VBControlExtender 与清单一起使用会导致错误 438(不支持此属性或方法)?
- laravel - 推送聊天中的消息不会立即刷新