DQ class
A utility class for building MongoDB queries.
The DQ class provides a set of static methods to construct MongoDB-compatible queries
in a more readable and structured way. It allows for easy creation of complex queries
with operations such as equality checks, logical operations (\$or
, \$and
), pattern matching,
and aggregation commands like grouping and sorting.
Example Usage:
var query = DQ.and([
DQ.field('name', DQ.like('John')),
DQ.field('age', DQ.eq(25)),
]);
var result = await collection.find(query).toList();
Constructors
- DQ()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
and(
List< Object?> list) → Map<String, Object?> - Constructs a logical AND query.
-
eq(
Object? value) → Object? - Returns a value for equality comparison.
-
field(
String name, Object? query) → Map< String, Object?> - Constructs a query for a specific field.
-
group(
Map< String, Object?> query) → Map<String, Object> - Constructs a MongoDB aggregation group stage.
-
hasIn(
Object? value) → Map< String, Object?> - Matches documents where the field's value is in the provided list.
-
hasNin(
Object? value) → Map< String, Object?> - Matches documents where the field's value is not in the provided list.
-
id(
String id) → Map< String, Object?> - Matches a document based on a string ID.
-
like(
String value, {String options = 'i'}) → Map< String, Object?> - Matches documents where the field's value matches a regular expression.
-
oid(
ObjectId id) → Map< String, Object?> - Matches a document based on its ObjectId.
-
or(
List< Object?> list) → Map<String, Object?> - Constructs a logical OR query.
-
order(
String? orderBy, [bool orderReverse = true]) → Map< String, Object> ? - Constructs an order/sorting query for MongoDB.
-
sum(
String field) → Map< String, Object?> - Constructs a sum aggregation operation.