OR query in mongo_dart

26 views Asked by At

I want to write a validation check where the query should return all users with a given username "OR" a given email. How could I write such a query using the mongo_dart package without having to query all the data and check it manually?

example query: if username=="x" or email=="y"

The tried this using the below query, but it did not work.

List<dynamic> all = await coll2.find({
        "or": [
          {"username": username},
          {"email": email}
        ]
      }).toList();

Moreover, using $or instead of or is raising syntax error in dart.

1

There are 1 answers

0
jQueeny On

You can try:

await coll2.find(
   where.eq('username', username).or(where.eq('email', email))
).toList();