Firebase .where() .limit() .orderBy() 的新命名空间
为了限制对 FirestoreDB 的获取,我尝试使用最近的命名空间来 getDocs()。
const firebaseColRef = collection(db, "collection")
这就是我尝试过的:
const firebaseColRef = collection(db, "collection").limit(x)
这:
const getDB = async () => {
const data = await getDocs(firebaseColRef).limit(x);
setFilmDB(data.docs.map((doc) => ({ ...doc.data(), id: doc.id })));
}
在这两种情况下,控制台都会提示:
Uncaught (in promise) TypeError: firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.collection(...).limit is not a function
我浏览了几个文档、教程和文章,但无法找到除上述名称空间之外的任何其他名称空间。并尝试任何可能的 .limit(x) 附加以获得除控制台提示符之外的任何其他结果。什么都没起作用。
我缺少什么?
有人能指出我正确的方向吗?
将不胜感激。 谢谢,安东尼
to limit the fetch to FirestoreDB I tried to use the recent namespace to getDocs().
const firebaseColRef = collection(db, "collection")
This is what I tried:
const firebaseColRef = collection(db, "collection").limit(x)
And this:
const getDB = async () => {
const data = await getDocs(firebaseColRef).limit(x);
setFilmDB(data.docs.map((doc) => ({ ...doc.data(), id: doc.id })));
}
In both cases the console prompts:
Uncaught (in promise) TypeError: firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.collection(...).limit is not a function
I went through several documentations, tutorials and articels and was not able to find any other namespace then the above mentioned. And tried any possible append of .limit(x) to get any other result than the console prompt. Nothing worked.
What am I missing ?
Can anyone point me in the right direction ?
Would be very appreciated.
Thanks, Anthony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几乎每个 Firebase 方法都是 Modular SDK 中的顶级函数,可以直接从相关 SDK 导入。尝试重构代码,如下所示。
同一查询的名称空间版本供参考:
您可以在 文档。
另请查看:
Almost every Firebase method is a top-level function in Modular SDK and can be imported directly from the relevant SDKs. Try refactoring the code as shown below.
The name-spaced version of the same query for reference:
You can find list of all functions in the new Firestore SDK in the documentation.
Also checkout: