firebase - 有 where 子句时 React Native Firebase 异步函数退出
问题描述
这有效
const getCatListings = async () => {
setIsLoading(true);
let snapshot = await listingsRef.orderBy('expires').limit(20).get();
if (!snapshot.empty) {
let newListings = [];
setLastDoc(snapshot.docs[snapshot.docs.length - 1]);
for (let i = 0; i < snapshot.docs.length; i++) {
newListings.push(snapshot.docs[i].data());
}
setData(newListings);
} else {
setLastDoc(null);
}
setIsLoading(false);
}
但是当我添加它时,它会在没有抛出任何错误来解释原因的情况下.where("categoryID", "==", category.id)
退出函数。setIsLoading(true)
let snapshot = await listingsRef.where("categoryID", "==", category.id).orderBy('expires').limit(20).get();
我读到“==”不需要 categoryID 上的 orderBy,但都试过了。任何帮助表示赞赏。
解决方案
当您在单个 firebase 查询中同时拥有 where 和 orderby 时,您需要在 firebase 中添加一个索引来支持此查询。
您可以在此处的官方文档中阅读它。
推荐阅读
- excel - 有没有办法按行值将 Excel 电子表格拆分为不同的文件?
- android - 如何使 MPAndroidChart 的折线图一次仅显示固定数量的值,例如 5
- python - 在 docker 中使用 pip 安装 python mysqlclient 时出现错误'OSError: mysql_config not found'
- python - 将两个数据框与条件配对
- android - 从最近使用的列表中删除应用程序时未调用 Android AlarmManager 接收器
- spring - 如何将标头添加到 Kafka 消息?
- c# - 通过 BLE 发送超过 20 个字节
- php - 不能显示小数
- visual-studio - 如何在 Visual Studio 的交互模式下访问 F# 模块
- excel - 使 UNIQUE() 函数在搜索重复项而不是整行时仅计算表的第一列