Skip to content

fix(mongodb): find never reads an unbounded result; .limit(0) is capped and says so (#1357) - #1696

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
fix/mongo-find-default-cap
Oct 17, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
fix/mongo-find-default-cap

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Refs #1357 (the default cap and the capped note; reading in chunks is not done).

MongoService.find applied a limit only when it was positive and then did stream.toList(). Every screen already passes one (the MQL default is 100, the document pager its page size, the editor and findOne 1, MCP its row cap), so the open paths were the API default and an explicit .limit(0), which MongoDB reads as "no limit": db.orders.find({}).limit(0) decoded the whole collection on the UI isolate (about 64 us per document, so 50,000 documents are a three-second wait).

  • effectiveMongoFindLimit(limit): null, 0 or a negative number become kMongoDefaultFindLimit (1000). An explicit positive limit is kept as given.
  • The MQL query summary says "Fetched 1000 documents (capped at 1000; give .limit(n) for more)" when .limit(0) reached the cap.

Not done from the issue: streaming the cursor in chunks instead of toList(). With the cap in place toList() holds at most 1000 documents unless the caller asks for more on purpose; chunking would be worth it together with the columnar work in #1549.

Tests: the limit mapping, and the summary text (ordinary find, .limit(0) at the cap, .limit(0) below it).

@github-actions github-actions Bot added performance Theme parser epic label: performance backend Backend database driver execution and queries P3 Low priority / Polish & Enhancements labels Oct 17, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit cfd6ac1 into dev Oct 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend database driver execution and queries P3 Low priority / Polish & Enhancements performance Theme parser epic label: performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant