Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/core/database/mongodb_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,26 @@ class MongoService {

return _withDb(connection, database, (db) async {
final coll = db.collection(collection);
final selector = filter ?? <String, dynamic>{};

final stream = coll.find(selector);
final results = <Map<String, dynamic>>[];
int count = 0;
await for (final doc in stream) {
if (skip != null && count < skip) {
count++;
continue;
}
if (limit != null && results.length >= limit) {
break;

final selector = where;
if (filter != null && filter.isNotEmpty) {
selector.raw(filter);
}
if (sort != null && sort.isNotEmpty) {
for (final entry in sort.entries) {
final isDesc = entry.value == -1 || entry.value == 'desc' || entry.value == 'DESC';
selector.sortBy(entry.key, descending: isDesc);
}
results.add(doc);
count++;
}
return results;
if (skip != null && skip > 0) {
selector.skip(skip);
}
if (limit != null && limit > 0) {
selector.limit(limit);
}

final stream = coll.find(selector);
return await stream.toList();
});
}

Expand Down
Loading