gpt4 book ai didi

node.js - 如何使用 Firebase-admin 为 NodeJs 设置 timestampsInSnapshots 设置?

转载 作者:IT老高 更新时间:2023-10-28 22:06:39 31 4
gpt4 key购买 nike

由于有关 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 = firebase.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.

不过,我找不到对 firestore“设置”的任何引用。像这样的东西会起作用吗? Typescript 定义说不...

import * as admin from "firebase-admin";

export const adminApp = admin.initializeApp();

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

最佳答案

我已将 firebase-admin 升级到 5.13.0,并在 initializeApp() 之后在我的 index.js 中使用以下 node.js 代码,该警告消失了,之后我的代码可以正常运行。

admin.initializeApp();
const settings = {/* your settings... */ timestampsInSnapshots: true};
admin.firestore().settings(settings);

关于node.js - 如何使用 Firebase-admin 为 NodeJs 设置 timestampsInSnapshots 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50799024/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com