猿问

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

我正在尝试在 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()

       }

    })

 })


哔哔one
浏览 143回答 2
2回答

慕妹3242003

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

郎朗坤

我通过采用数组字段类型而不是子集合找到了解决方法。这是我的代码示例:&nbsp;&nbsp;var&nbsp;coll&nbsp;=&nbsp;this.firestore.collection('credentials',&nbsp;ref&nbsp;=>&nbsp;ref.where('tags',&nbsp;'array-contains-any',&nbsp;['agile']).orderBy('shortName'));&nbsp;//&nbsp;selects&nbsp;part&nbsp;of&nbsp;collection&nbsp;where&nbsp;roomId&nbsp;=&nbsp;roomStripped,&nbsp;sorted&nbsp;by&nbsp;name返回 coll.snapshotChanges();我有一个名为凭据的主要集合,以及每个文档中的标签列表。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答