【发布时间】:2017-11-29 12:27:06
【问题描述】:
我了解 Firestore 不支持查询的逻辑 OR。 我的想法是创建多个查询并在客户端合并结果。 我正在开发一个新闻应用程序,我正在尝试获取所有包含我用户兴趣标签的文章(例如技术、音乐等) 一个普通用户有 20 个标签,所以我将提出 20 个不同的请求。
有没有人有链接多个请求并在所有结果到达时返回唯一承诺的经验。?
我正在使用 js sdk
我的数据结构:
文章(收藏)
-article (document)
--id: 10
--time: 1502144665
--title: "test title"
--text: "test text"
--tags(obj)
---technology: 1502144665,
---politics: 1502144665,
---sports: 1502144665
所以我需要创建多个数据库请求,如下所示。
user.tags = ["technology","politics","sports","architecture","business"];
for (var i = 0; i < user.tags.length; i++) {
db.collection('articles').where(user.tags[i], '>', 0).orderBy(user.tags[i]))
.get()
.then(() => {
// ... push to article array
});)
}
我试图弄清楚如何在每个请求完成时创建一个承诺/回调。
【问题讨论】:
标签: firebase google-cloud-firestore