How to search for documents where a field
starts with some term
?
Example: finding all documents in someCollection
where someField
starts with "foo"
So fields with "foo", "food", "fools" would be returned but "fop", "fopp" would not.
How to search for documents where a field
starts with some term
?
Example: finding all documents in someCollection
where someField
starts with "foo"
So fields with "foo", "food", "fools" would be returned but "fop", "fopp" would not.
Try this,
Stream streamQuery;
streamQuery = firestore.collection('someCollection')
.where('someField', isGreaterThanOrEqualTo: searchKey)
.where('someField', isLessThan: searchKey +'z')
.snapshots();
This is a dart adaptation of a java answer
final strFrontCode = term.substring(0, term.length - 1);
final strEndCode = term.characters.last;
final limit =
strFrontCode + String.fromCharCode(strEndCode.codeUnitAt(0) + 1);
final snap = await FirebaseFirestore.instance
.collection('someCollection')
.where('someField', isGreaterThanOrEqualTo: term)
.where('someField', isLessThan: limit)
.get();