【问题标题】:Angular 6 - AnguarFire - query a collection using multiple document fieldsAngular 6 - AnguarFire - 使用多个文档字段查询集合
【发布时间】:2019-04-29 02:46:28
【问题描述】:

我在我的项目中使用 AngularFire 和 Cloud Firestore,我需要使用多个条件(在哪里)对集合进行查询。

我尝试使用此代码,但它忽略了第二个条件。

 this.itemCollection = this.afs.collection<Item>('items', ref => {

 return ref
         .where('size', '==', 'large')
         .where('brand', '==', 'some-brand')
 })
 this.items = this.itemCollection.valueChanges();

我做错了什么,如何在 AngularFire 中应用多个条件?

【问题讨论】:

    标签: angular firebase google-cloud-firestore angularfire2


    【解决方案1】:

    您的代码需要:

    this.itemCollection = this.afs.collection<Item>('items', ref => ref.where('size', '==', 
    'large').where('brand', '==', 'some-brand'))
    return this.items = this.itemCollection.valueChanges();
    

    【讨论】:

      【解决方案2】:

      使用多个where 子句对不同字段的查询无效 [1][2]。 这不是真的 => 当查询类型相同时,firebase 支持多个 where 查询,例如“==”&&“==”。 3 只有在混合类型的情况下,例如“==” && “=>”,firebase 才会拒绝它。

      但是,请查看此response 以了解关于 SO 的其他问题:Query based on multiple where clauses in Firebase

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-29
        • 2020-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多