getAll method
Retrieves multiple documents from the collection with flexible options.
This method provides comprehensive querying capabilities including filtering, sorting, pagination, and field projection. The results are automatically processed through the form validation system.
Parameters:
selector
- Query selector for filtering documentsfilter
- Additional filter criteriafindOptions
- MongoDB find operation optionshint
- Index hint for query optimizationskip
- Number of documents to skip (for pagination)sort
- Sort order specificationlimit
- Maximum number of documents to returnhintDocument
- Document-based index hintprojection
- Fields to include/exclude in resultsrawOptions
- Raw MongoDB query options
Returns a list of documents as maps, processed through form validation.
Example:
var users = await collection.getAll(
filter: {'status': 'active'},
sort: {'createdAt': -1},
limit: 10,
skip: 20,
);
Implementation
Future<List<Map<String, Object?>>> getAll({
SelectorBuilder? selector,
Map<String, Object?>? filter,
FindOptions? findOptions,
String? hint,
int? skip,
Map<String, Object>? sort,
int? limit,
Map<String, Object>? hintDocument,
Map<String, Object>? projection,
Map<String, Object>? rawOptions,
}) async {
skip ??= 0;
skip = skip < 1 ? null : skip;
var results = <Map<String, Object?>>[];
var result = collection.modernFind(
selector: selector,
filter: filter,
findOptions: findOptions,
hint: hint,
skip: skip,
sort: sort,
limit: limit,
hintDocument: hintDocument,
projection: projection,
rawOptions: rawOptions,
);
List<String>? selectedFields;
if (selector != null && selector.paramFields.isNotEmpty) {
selectedFields = selector.paramFields.keys.toList();
}
for (var element in await result.toList()) {
results.add(await toModel(element, selectedFields: selectedFields));
}
return results;
}