0

My Firestore set up is the following:

Collection : Users | DocumentID : [Auto-generated] | Fields -> name: robert downey jr, username: iron_man

I would like to query this document with a search query like "robert" or "rob" or "iron" or "ir". How do I do this in Firestore? I tried whereArrayContains() but that query looks for perfect match rather than starts with

Anudeep Ananth
  • 388
  • 2
  • 14

1 Answers1

1

You won't be able to do this in one query, because Firestore does not support logical OR queries that span multiple fields. What you can do instead is make two queries, one for name, and the other for username that do string prefix sorts (read other questions about that here, here, here). Then, after you do both queries, merge the results on the client to build the final list of results.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441