Skip to content

Performance: Client-Side Skip/Limit in MongoDB Pagination #185

Description

@ZhuchkaTriplesix

In mongodb_service.dart, pagination (skip and limit) is executed on the client side over a full stream of documents returned by the database:

final stream = coll.find(selector);
...
await for (final doc in stream) {
  if (skip != null && count < skip) {
    count++;
    continue; // Discard client-side
  }
  ...
}

This causes heavy network bandwidth and CPU usage if the user navigates deep into a large collection.

Steps to fix:
Inject skip and limit operations directly into the query selector builder or options map on the database side before fetching the stream:

final selectorBuilder = where;
if (skip != null) selectorBuilder.skip(skip);
if (limit != null) selectorBuilder.limit(limit);
final stream = coll.find(selectorBuilder);

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions