[英]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.