为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 angular 查询消防商店子集合?

如何使用 angular 查询消防商店子集合?

哔哔one 2021-10-21 13:57:48
我正在尝试在 ionic 4 应用程序/角度应用程序中查询 Firestore 子集合。我的数据库如下所示 people(id) ----> tasks(id){ description : this is a description about a cat,<br>  title: this is a cat <br>  category: cat } 我正在使用 Firestore 函数来查询集合中的所有数据。这是 Firestore 函数的样子:import * as functions from 'firebase-functions';import * as admin from 'firebase-admin'admin.initializeApp()    export const getFeed = functions.https.onCall(async (req,res) =>{    const docs = await     admin.firestore().collection('people').limit(5).get()    return docs.docs.map(doc => {    return {        postID: doc.id,        ...doc.data()       }    }) })打字稿 home.ts 文件如下所示:    const getFeed = this.aff.httpsCallable('getFeed')    this.posts = getFeed({}).subscribe(data=> {      console.log(data)      // this.posts = data        })    }我尝试使用 array-contains 选项进行查询,但它不起作用。该数组在控制台上显示为空。   export const getFeed = functions.https.onCall(async (req,res) =>{    const docs = await     admin.firestore().collection('people').where("category",     "array-     contains", "cat").limit(5).get()    return docs.docs.map(doc => {    return {        postID: doc.id,        ...doc.data()       }    }) })
查看完整描述

2 回答

?
慕妹3242003

TA贡献1824条经验 获得超6个赞

您的问题不是很清楚,但看起来category您的数据库字段实际上并不是列表类型字段。 array-contains仅当值是一个列表时才有效,如果它只是一个字符串值,则无效。如果它只是一个字符串,则对其使用==过滤器。


查看完整回答
反对 回复 2021-10-21
?
郎朗坤

TA贡献1921条经验 获得超9个赞

我通过采用数组字段类型而不是子集合找到了解决方法。

这是我的代码示例:

  var coll = this.firestore.collection('credentials', ref => ref.where('tags', 'array-contains-any', ['agile']).orderBy('shortName')); // selects part of collection where roomId = roomStripped, sorted by name

返回 coll.snapshotChanges();

我有一个名为凭据的主要集合,以及每个文档中的标签列表。


查看完整回答
反对 回复 2021-10-21
  • 2 回答
  • 0 关注
  • 142 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信