Skip to content

fix: MongoDB default batch size changed from 1000 to 100 without announcement#10085

Merged
mtrezza merged 6 commits intoparse-community:alphafrom
mtrezza:fix/mongodb-batch-size
Mar 3, 2026
Merged

fix: MongoDB default batch size changed from 1000 to 100 without announcement#10085
mtrezza merged 6 commits intoparse-community:alphafrom
mtrezza:fix/mongodb-batch-size

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Mar 2, 2026

Pull Request

Issue

MongoDB Node.js driver 7.0.0 removed the default batchSize of 1000 on getMore cursor 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 mongodb from 6.20.0 to 7.0.0.

Approach

Add a configurable databaseOptions.batchSize option (default: 1000) that is applied to all MongoDB cursor operations (find, aggregate) in both MongoStorageAdapter and GridFSBucketAdapter. This restores the MongoDB driver v6 behavior while allowing users to tune the value via configuration or the PARSE_SERVER_DATABASE_BATCH_SIZE environment variable.

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • New Features

    • Added a configurable batchSize option for MongoDB cursor operations (default 1000) that applies to reads, aggregations and file streaming (GridFS); leaving it unset uses driver defaults.
    • Server now injects database defaults when no custom database adapter is configured.
  • Documentation

    • Updated database options docs to describe batchSize and its memory vs. network trade-offs.
  • Tests

    • Added tests validating batchSize propagation, filtering from driver options, and default behavior.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 2, 2026

🚀 Thanks for opening this pull request!

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Mar 2, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Important

Review skipped

This 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 @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Configuration & Defaults
src/Options/Definitions.js, src/Options/index.js, src/Options/docs.js, src/defaults.js, src/ParseServer.ts
Introduce new batchSize DatabaseOptions (env PARSE_SERVER_DATABASE_BATCH_SIZE, default 1000); export DatabaseOptionDefaults; add batchSize to ParseServerDatabaseOptions filtering; inject defaults into ParseServer when no databaseAdapter is set.
Mongo Storage / Collection
src/Adapters/Storage/Mongo/MongoStorageAdapter.js, src/Adapters/Storage/Mongo/MongoCollection.js
Add private _batchSize (initialized from mongoOptions); update find, _rawFind, and aggregate signatures to accept/forward batchSize so underlying MongoDB driver calls include { batchSize }.
GridFS Bucket Adapter
src/Adapters/Files/GridFSBucketAdapter.js
Store _batchSize from mongoOptions and pass { batchSize: this._batchSize } to all bucket.find usages (deleteFile, getMetadata, handleFileStream, rotateEncryptionKey, getFileData retrievals).
Tests
spec/GridFSBucketStorageAdapter.spec.js, spec/MongoStorageAdapter.spec.js
Add tests verifying _batchSize initialization, that batchSize is removed from options sent to MongoClient, that find/aggregate calls receive the configured batchSize, and default handling.
Types
types/Options/index.d.ts
Add optional batchSize?: number to DatabaseOptions type declarations.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: addressing MongoDB's default batch size behavior change from driver v6 to v7, with a configurable default of 1000 to restore prior performance.
Description check ✅ Passed The description provides clear context (issue, root cause, regression origin) and documents the approach with appropriate task checklist completion, meeting template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

batchSize is dropped in find(), so batching is not applied to normal query reads.

_rawFind supports batchSize, but find() neither destructures nor forwards it (including retry path). This means adapter-provided batch size is ignored for find() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 62e9132 and e0b695c.

📒 Files selected for processing (7)
  • src/Adapters/Files/GridFSBucketAdapter.js
  • src/Adapters/Storage/Mongo/MongoCollection.js
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
  • src/Options/Definitions.js
  • src/Options/docs.js
  • src/Options/index.js
  • src/defaults.js

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 2, 2026
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.61%. Comparing base (aca4dad) to head (4d1f157).
⚠️ Report is 5 commits behind head on alpha.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6f4b4 and 5a0eb8e.

📒 Files selected for processing (3)
  • spec/MongoStorageAdapter.spec.js
  • src/ParseServer.ts
  • src/defaults.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • spec/MongoStorageAdapter.spec.js

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
spec/MongoStorageAdapter.spec.js (1)

153-161: Prefer behavior-based assertion over private field access.

On Line 160, asserting adapter._batchSize couples 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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a0eb8e and eaf85c9.

📒 Files selected for processing (2)
  • spec/MongoStorageAdapter.spec.js
  • src/Adapters/Storage/Mongo/MongoCollection.js

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 3, 2026
@mtrezza mtrezza merged commit 8f17397 into parse-community:alpha Mar 3, 2026
22 checks passed
parseplatformorg pushed a commit that referenced this pull request Mar 3, 2026
## [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))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 9.4.1-alpha.1

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 3, 2026
@mtrezza mtrezza deleted the fix/mongodb-batch-size branch March 3, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants