【问题标题】:Case insensitive query on Firestore [duplicate]Firestore上不区分大小写的查询[重复]
【发布时间】:2018-08-19 12:42:42
【问题描述】:

您能告诉我如何在 Firestore 上进行不区分大小写的查询吗?

例如 Hallway 和 hallway 两者必须相同。但下面的查询会进行精确搜索。即如果 db 有 Hallway 并且我尝试搜索 hallway 然后它显示 no records。

  getSpecificTempBudgetGroup(name: string): AngularFirestoreCollection<BudgetGroup> {
    return this.fireStore.collection<BudgetGroup>(`members/${this.authenticationProvider.member.id}/budgetGroups`, ref => ref
      .where('name', '==', name)
    );
  }

我也试过toLowerCase()。但没有运气:(有什么线索吗?

getSpecificTempBudgetGroup(name: string): AngularFirestoreCollection<BudgetGroup> {
        return this.fireStore.collection<BudgetGroup>(`members/${this.authenticationProvider.member.id}/budgetGroups`, ref => ref
          .where('name.toLowerCase()', '==', name.toLowerCase())
        );
      }

注意:我也看到了可能重复的答案。但它并没有给我的用例提供太多的想法。但是我使用下面提到的 MongoDB 答案获得了有用的信息。

【问题讨论】:

    标签: angular typescript firebase ionic3 google-cloud-firestore


    【解决方案1】:

    我在 db 上创建了一个属性,就像 lowerCaseName 一样,之后更改了我的查询,如下所示。我受到this MongoDB answer 的启发。

      getSpecificTempBudgetGroup(name: string): AngularFirestoreCollection<BudgetGroup> {
        return this.fireStore.collection<BudgetGroup>(`members/${this.authenticationProvider.member.id}/budgetGroups`, ref => ref
          .where('lowerCaseName', '==', name.toLowerCase())
        );
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 2018-10-04
      • 2018-11-21
      相关资源
      最近更新 更多