javascript - 如何在firestore(firebase)过滤数据并获取过滤后的数据?如何在数据库集合中使用“等于”?
问题描述
export const getSprintByProjectId = (key) => async (dispatch) => {
console.log(key);
try {
dispatch(loaderOn());
const result = await db
.collection("sprints")
.orderByChild("projectId")
.equalTo(key);
} catch (error) {
dispatch(errorOn());
} finally {
dispatch(loaderOff());
}
};
试图通过 ID 获取数据
解决方案
您的 JS 代码看起来像是在尝试在 Firestore 上使用实时数据库查询方法。我希望它看起来更像:
export const getSprintByProjectId = (key) => async (dispatch) => {
console.log(key);
try {
dispatch(loaderOn());
const result = await db
.collection("sprints")
.where("projectId", "==", key)
.get();
console.log(result.docs.map(d => d.data());
} catch (error) {
dispatch(errorOn());
} finally {
dispatch(loaderOff());
}
};
推荐阅读
- c# - 支持“Equals”重载和隐式运算符的 Expression.Equal 解决方案
- c# - Selenium 自动化与静态页面对象模型
- c# - 如何在不使用旧版驱动程序的情况下在 MongoDB C# 驱动程序 2.1 版中实现 CommandDocument
- c++ - 找到“\ 0”时如何停止读取管道()
- node.js - 玩笑挂在 i18n.configure()
- android - xamarin.android中的drawerlayout + CoordinatorLayout
- c# - 列表
> 结果 = 新列表 >() - java - 尝试设置数据绑定时出错
- php - PHP 7.4 递归箭头函数
- google-cloud-platform - Dialogflow v2 - 在没有任何库的情况下发出 REST API 请求