getAll method

Future<List<Map<String, Object?>>> getAll({
  1. SelectorBuilder? selector,
  2. Map<String, Object?>? filter,
  3. FindOptions? findOptions,
  4. String? hint,
  5. int? skip,
  6. Map<String, Object>? sort,
  7. int? limit,
  8. Map<String, Object>? hintDocument,
  9. Map<String, Object>? projection,
  10. Map<String, Object>? rawOptions,
})

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 documents
  • filter - Additional filter criteria
  • findOptions - MongoDB find operation options
  • hint - Index hint for query optimization
  • skip - Number of documents to skip (for pagination)
  • sort - Sort order specification
  • limit - Maximum number of documents to return
  • hintDocument - Document-based index hint
  • projection - Fields to include/exclude in results
  • rawOptions - 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;
}