My Firestore set up is the following:
Collection : Users |
DocumentID : [Auto-generated] |
name: robert downey jr,
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
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.