Admin SDK无法为Firestore设置设置 [英] Admin SDK cannot set settings for Firestore

查看:100
本文介绍了Admin SDK无法为Firestore设置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我最近收到了这个警告:

So, I've been getting this warning recently:


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

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);




通过此更改,存储在Cloud Firestore中的时间戳将被读取为
返回Firebase Timestamp对象而不是系统Date对象。
所以你还需要更新期望日期的代码而不是
期望一个时间戳。例如:

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();




请在启用新$ b时审核所有现有的日期用法$ b行为。在将来的版本中,行为将更改为新的
行为,因此如果您不按照这些步骤操作,您的应用程序可能会突然停止。

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.

我正在尝试在我的云端功能代码中的管理SDK中实现建议的更正,因为我正在做的大部分工作都在那里。

I am trying to implement the suggested correction in the admin SDK in my Cloud Functions code, since most of what I am doing is through there.

I尝试使用 admin.firestore()。settings({timestampsInSnapshots:true})但收到了以下警告:

I tried using admin.firestore().settings({ timestampsInSnapshots: true }) but got the following warning:


admin.firestore(...)。设置不是函数

admin.firestore(...).settings is not a function

如何解决?

推荐答案

我遇到了同样的问题。我不得不更新firebase-functions和firebase-admin。

I had the same problem. I had to update firebase-functions and firebase-admin.

要升级,请转到您的CLI,然后

To upgrade, go to your CLI, then

ProjectDirectory > Functions > npm install firebase-functions@latest firebase-admin@latest --save

然后,在顶部,在触发函数之前:

Then, at the top, before triggering functions:

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

这篇关于Admin SDK无法为Firestore设置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆