2

Could you tell me how can I do case insensitive query on Firestore?

e.g. Hallway and hallway both must be the same. But below query does exact search. i.e. If db has Hallway and I tried to search hallway then it shows no records.

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

I have tried with toLowerCase() too. But no luck :( Any clue?

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

Note: I saw the possible duplicate answer too. But it didn't give that much of idea to my use case. But I got useful info using MongoDB answer which I have mentioned below.

Sampath
  • 63,341
  • 64
  • 307
  • 441

1 Answers1

2

I have created a property on db like so lowerCaseName and after that changed my query as shown below. I have inspired about this solution by 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())
    );
  }
Sampath
  • 63,341
  • 64
  • 307
  • 441