I writing a mobile application that requires to search for a document that has two fields that satisfy the search query.
I got the original idea of searching in Firestore from this answer
I tried to modify it to get achieve my required result but I'm getting an error. Here is my code which is an extension method on CollectionReference<User>
:
CollectionReference<User> get all {
return FirebaseFirestore.instance.collection('users').withConverter<User>(
fromFirestore: (snapshot, _) => User.fromFirestore(snapshot),
toFirestore: (User user, options) => user.toFirestore(),
);
}
extension UserQueryExtension on CollectionReference<User> {
Query<User> search(String search) {
if (search.isEmpty) {
return this;
}
return where(
Filter.or(
Filter.and(
Filter('name', isGreaterThanOrEqualTo: search),
Filter('name', isLessThan: '${search}z'),
),
Filter.and(
Filter('surname', isGreaterThanOrEqualTo: search),
Filter('surname', isLessThan: '${search}z'),
),
),
);
}
}
When I run the code I get the following error:
Exception has occurred.
PlatformException (PlatformException(error, An error occurred while parsing query arguments, see native logs for more information. Please report this issue., null, null))
I would appreciate the help.