I am looking to add a simple search field, would like to use something like
collectionRef.where('name', 'contains', 'searchTerm')
I tried using where('name', '==', '%searchTerm%')
, but it didn't return anything.
I agree with @Kuba's answer, But still, it needs to add a small change to work perfectly for search by prefix. here what worked for me
For searching records starting with name queryText
collectionRef.where('name', '>=', queryText).where('name', '<=', queryText+ '\uf8ff')
.
The character \uf8ff
used in the query is a very high code point in the Unicode range (it is a Private Usage Area [PUA] code). Because it is after most regular characters in Unicode, the query matches all values that start with queryText
.