fix: MongoDB default batch size changed from 1000 to 100 without announcement#10085
Conversation
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Important Review skippedThis PR was authored by the user configured for CodeRabbit reviews. By default, CodeRabbit skips reviewing PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback. To trigger a single review, invoke the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds a configurable MongoDB cursor batchSize (env PARSE_SERVER_DATABASE_BATCH_SIZE, default 1000) and threads it through ParseServer defaults, MongoStorageAdapter/MongoCollection, and GridFSBucketAdapter so driver calls include the configured batchSize when present. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ParseServer
participant MongoStorageAdapter
participant MongoCollection
participant GridFSBucketAdapter
participant MongoDB
Client->>ParseServer: Start / provide mongoOptions (may include batchSize)
ParseServer->>ParseServer: inject DatabaseOptionDefaults (batchSize)
ParseServer->>MongoStorageAdapter: construct(mongoOptions filtered for client)
MongoStorageAdapter->>MongoCollection: find(query, { batchSize: this._batchSize })
MongoStorageAdapter->>GridFSBucketAdapter: instantiate(with _batchSize)
GridFSBucketAdapter->>MongoDB: bucket.find(..., { batchSize: N })
MongoCollection->>MongoDB: find(..., { batchSize: N })
MongoDB-->>MongoCollection: cursor (batching behavior)
MongoDB-->>GridFSBucketAdapter: cursor (batching behavior)
MongoCollection-->>MongoStorageAdapter: results
GridFSBucketAdapter-->>Client: stream/file data
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Adapters/Storage/Mongo/MongoCollection.js (1)
16-29:⚠️ Potential issue | 🔴 Critical
batchSizeis dropped infind(), so batching is not applied to normal query reads.
_rawFindsupportsbatchSize, butfind()neither destructures nor forwards it (including retry path). This means adapter-provided batch size is ignored forfind()operations.🐛 Proposed fix
find( query, { skip, limit, sort, keys, maxTimeMS, + batchSize, readPreference, hint, caseInsensitive, explain, comment, } = {} ) { @@ return this._rawFind(query, { skip, limit, sort, keys, maxTimeMS, + batchSize, readPreference, hint, caseInsensitive, explain, comment, @@ this._rawFind(query, { skip, limit, sort, keys, maxTimeMS, + batchSize, readPreference, hint, caseInsensitive, explain, comment, })Also applies to: 36-47, 65-76, 89-103
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Adapters/Storage/Mongo/MongoCollection.js` around lines 16 - 29, The find() method is dropping the batchSize option: include batchSize in the destructured options list for find(...) and ensure it is forwarded to _rawFind(...) (including the retry path) so adapter-provided batch sizes are honored; update all similar destructurings/calls (the other find overloads/branches that destructure options and call _rawFind) to accept and pass batchSize through as well.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/Adapters/Storage/Mongo/MongoCollection.js`:
- Around line 16-29: The find() method is dropping the batchSize option: include
batchSize in the destructured options list for find(...) and ensure it is
forwarded to _rawFind(...) (including the retry path) so adapter-provided batch
sizes are honored; update all similar destructurings/calls (the other find
overloads/branches that destructure options and call _rawFind) to accept and
pass batchSize through as well.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/Adapters/Files/GridFSBucketAdapter.jssrc/Adapters/Storage/Mongo/MongoCollection.jssrc/Adapters/Storage/Mongo/MongoStorageAdapter.jssrc/Options/Definitions.jssrc/Options/docs.jssrc/Options/index.jssrc/defaults.js
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10085 +/- ##
==========================================
+ Coverage 92.19% 92.61% +0.42%
==========================================
Files 191 191
Lines 15762 15776 +14
Branches 176 180 +4
==========================================
+ Hits 14531 14611 +80
+ Misses 1215 1153 -62
+ Partials 16 12 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/defaults.js`:
- Line 49: Add the missing batchSize declaration to the TypeScript
DatabaseOptions interface so TypeScript users can type this option; locate the
DatabaseOptions interface in types/Options/index.d.ts and add a batchSize?:
number (optional) entry that matches the runtime definitions in
src/Options/index.js and src/Options/Definitions.js, and update any
JSDoc/comment for DatabaseOptions if present to document the option.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
spec/MongoStorageAdapter.spec.jssrc/ParseServer.tssrc/defaults.js
🚧 Files skipped from review as they are similar to previous changes (1)
- spec/MongoStorageAdapter.spec.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
spec/MongoStorageAdapter.spec.js (1)
153-161: Prefer behavior-based assertion over private field access.On Line 160, asserting
adapter._batchSizecouples this test to internals; asserting observed driver call options would be more refactor-safe.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/MongoStorageAdapter.spec.js` around lines 153 - 161, The test currently asserts the private field adapter._batchSize; instead, keep behavior-based verification by exercising a database operation that uses the batch size and spying on the underlying driver call to verify the option is passed as 1000. In the spec that calls reconfigureServer and obtains Config.get(Parse.applicationId).database.adapter, replace the direct _batchSize assertion with a spy/mock on the adapter's underlying collection find (or the Mongo client collection method) and perform a query, then assert the driver was invoked with options.batchSize (or equivalent) equal to 1000.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@spec/MongoStorageAdapter.spec.js`:
- Around line 153-161: The test currently asserts the private field
adapter._batchSize; instead, keep behavior-based verification by exercising a
database operation that uses the batch size and spying on the underlying driver
call to verify the option is passed as 1000. In the spec that calls
reconfigureServer and obtains Config.get(Parse.applicationId).database.adapter,
replace the direct _batchSize assertion with a spy/mock on the adapter's
underlying collection find (or the Mongo client collection method) and perform a
query, then assert the driver was invoked with options.batchSize (or equivalent)
equal to 1000.
## [9.4.1-alpha.1](9.4.0...9.4.1-alpha.1) (2026-03-03) ### Bug Fixes * MongoDB default batch size changed from 1000 to 100 without announcement ([#10085](#10085)) ([8f17397](8f17397))
|
🎉 This change has been released in version 9.4.1-alpha.1 |
Pull Request
Issue
MongoDB Node.js driver 7.0.0 removed the default batchSize of 1000 on
getMorecursor commands. Without this default, the MongoDB server sends up to 16 MiB per batch instead of 1000 documents. This causes increased memory pressure and GC pauses under load, leading to higher tail latency and increased client timeout errors (HTTP 499) from load balancers.The issue was introduced in parse-server 9.2.0-alpha.4 by #10027 when upgrading
mongodbfrom 6.20.0 to 7.0.0.Approach
Add a configurable
databaseOptions.batchSizeoption (default: 1000) that is applied to all MongoDB cursor operations (find,aggregate) in bothMongoStorageAdapterandGridFSBucketAdapter. This restores the MongoDB driver v6 behavior while allowing users to tune the value via configuration or thePARSE_SERVER_DATABASE_BATCH_SIZEenvironment variable.Tasks
Summary by CodeRabbit
New Features
Documentation
Tests