0

I want to search the dataset in Firestore whose starting character(s) matches the data as for this example:

  • I am building an application in which I save the record for cars in cars collection and there is a data field of carName for every car document. If I have car named as "BMW" and "Belta" then I only type "B" to search the car and it gives me results for both "Belta and BMW" by matching the first character

Is this possible?

If my query is not conveying properly then please tell me and I will make the question more readable.

Sergi
  • 135
  • 7
Usama Abdul Razzaq
  • 643
  • 2
  • 10
  • 19
  • You can try use 'whereGreaterThanOrEqual' - FirebaseFirestore.getInstance().collection("CarsCollection").whereGreaterThanOrEqualTo("CarName", "al"); – MukulSharma Mar 22 '21 at 16:25

1 Answers1

0

Yes, it is possible.

Following your example, for searching cars that start with "B" you could try:

db.collection('cars')
    .where('carName', '>=', 'B')
    .where('carName', '<', 'C');

If you would like to do that with any letter, you could check here for different examples on how to do it.

Sergi
  • 135
  • 7