小编Nic*_*fli的帖子

多个Firestore查询,单个承诺/回调

我知道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
Run Code Online (Sandbox Code Playgroud)

所以我需要创建多个db请求,如下所示.

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
  });)
}
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚如何在每个请求完成时创建一个promise/callback.

firebase google-cloud-firestore

1
推荐指数
2
解决办法
5022
查看次数

标签 统计

firebase ×1

google-cloud-firestore ×1