简体   繁体   English

Firebase-admin Firestore node.js 与模块化 v9 js sdk 共享逻辑

[英]Firebase-admin Firestore node.js share logic with modular v9 js sdk

What is the recommended way to share Firestore api logic (between the admin node.js and the js web) when upgrading to the web v9 modular sdk?升级到 web v9 模块化 sdk 时,推荐的共享 Firestore api 逻辑(在管理员 node.js 和 js web 之间)的方法是什么? The way I did it before was just supplying the db (and deleteField) if it was used by a serverless function.如果它被无服务器函数使用,我之前这样做的方式只是提供 db(和 deleteField)。

// admin db init
import { FieldValue, getFirestore } from "firebase-admin/firestore"
const FSAdmin = createFirebaseAdminApp(options);
const db = getFirestore(FSAdmin)

That no longer seems to work as if you try to use the getFirestore(FSAdmin) with the v9 docRef doc(db, collectionName, documentID) it will give you an error:这似乎不再起作用,就好像您尝试将getFirestore(FSAdmin)与 v9 docRef doc(db, collectionName, documentID)一起使用它会给您一个错误:

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore FirebaseError:collection() 的第一个参数应为 CollectionReference、DocumentReference 或 FirebaseFirestore

It seems like the function getFirestore(FSAdmin) and getFirestore(FSAdmin) does not get what it expects.似乎函数 getFirestore(FSAdmin) 和 getFirestore(FSAdmin) 没有得到它所期望的。 As I can't see your complete configuration and debug information, it's a bit difficult to tell the full context of the error.由于我看不到您的完整配置和调试信息,因此很难说出错误的完整上下文。 As it is stated in the Firebase docs firebase docs , make sure to call initializeApp(firebaseConfig);正如 Firebase docs firebase docs中所述,请确保调用 initializeApp(firebaseConfig); including the proper configuration before you use Firestore in your app.在您的应用中使用 Firestore 之前包括正确的配置。 Also check that you have the latest version of all your Firebase packages installed.还要检查您是否安装了所有 Firebase 软件包的最新版本。 I also know that Firebase has recently got quite some library changes, as Firebase also strives to minify itself.我也知道 Firebase 最近对库进行了相当多的更改,因为 Firebase 也在努力缩小自身。

Note that there are two packages:请注意,有两个包:

const { initializeApp } = require('firebase-admin/app'); const { initializeApp } = require('firebase-admin/app');

and

import { initializeApp } from 'firebase/app';从'firebase/app'导入{initializeApp};

In addition, I could not find createFirebaseAdminApp() and getFirestore() in the current function list of the Firebase docs, so I think they changed the signature completely.另外,我在 Firebase 文档的当前函数列表中找不到 createFirebaseAdminApp() 和 getFirestore(),所以我认为他们完全改变了签名。

Firebase/JS all signatures. Firebase/JS 所有签名。

I hope I could help you at least a bit.我希望我能帮助你至少一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase JS SDK 包是否与云函数的 Node.js 环境兼容? 为什么要使用 firebase-admin? - Is the firebase JS SDK package compatible with the Node.js environment of a cloud function? Why use firebase-admin? Node.js 12.x AWS lambda 不使用 firebase-admin 实时数据库返回 - Node.js 12.x AWS lambda does not return using firebase-admin realtime database 如何使用 Firebase Modular SDK V9 增加 Firestore 中的数据字段? - How to increment a data field in Firestore using Firebase Modular SDK V9? 从 Firebase Firestore 中删除字段/键带有句点/标点符号 (".") 的字段 - 模块化 v9 JavaScript SDK - Delete a field from Firebase Firestore where the field/key has a period/punctuation (".") - modular v9 JavaScript SDK 如何在 firestore 中创建自定义 id 文档(Firebase modular SDK (v9)) - How to create a custom id document in firestore(Firebase modular SDK (v9)) Firestore 查询具有相似数组的文档(Node.js/Admin SDK) - Firestore Query Documents With Similar Array (Node.js/Admin SDK) 使用 Modular SDK v9 的 Firestore 条件 where 子句 - Firestore conditional where clause using Modular SDK v9 如何使用firebase-admin模块使用Node.js从Firebase数据库返回有序数据? - How can I return ordered data from Firebase database with Node.js using the firebase-admin module? 在 Firebase Firestore 中查询整个集合时如何获取对象属性的子集? 使用JS客户端sdk v9 - How to get a subset of object's properties when querying an entire collection in Firebase Firestore? Using JS client sdk v9 有没有办法在没有 Firebase-Admin 的情况下在 Firebase Firestore JS 中使用 FieldValue.serverTimestamp() - Is there any way to use FieldValue.serverTimestamp() in Firebase Firestore JS without Firebase-Admin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM