Skip to content

feat: Extend storage adapter interface to optionally return matchedCount and modifiedCount from DatabaseController.update with many: true#10353

Merged
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:feat/return-changes-in-update
Mar 30, 2026
Merged

feat: Extend storage adapter interface to optionally return matchedCount and modifiedCount from DatabaseController.update with many: true#10353
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:feat/return-changes-in-update

Conversation

@mtrezza
Copy link
Copy Markdown
Member

@mtrezza mtrezza commented Mar 29, 2026

Summary

  • DatabaseController.update with { many: true } now returns { matchedCount, modifiedCount } instead of {}
  • Adds UpdateManyResult type to StorageAdapter interface as an optional return value for updateObjectsByQuery
  • MongoDB adapter provides numeric counts; other adapters return undefined (non-breaking)

Test plan

  • Multiple docs matched and modified
  • Matched but not modified (idempotent update)
  • Zero matches returns { matchedCount: 0, modifiedCount: 0 }
  • Op-based updates return only count fields
  • Tests are MongoDB-only via describe_only_db('mongo')

Summary by CodeRabbit

  • New Features

    • Multi-document update operations now return metadata with matched and modified counts (counts may be undefined if the storage adapter doesn't provide them).
  • Tests

    • Added comprehensive tests for multi-document updates covering multiple matches, matches with no actual changes, no matches, operation-style updates, and the raw adapter response when sanitization is skipped.

@parse-github-assistant
Copy link
Copy Markdown

parse-github-assistant bot commented Mar 29, 2026

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement.

@parseplatformorg
Copy link
Copy Markdown
Contributor

parseplatformorg commented Mar 29, 2026

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

Status Scan Engine 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
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

Adds a Mongo-only bulk-update path: adapters may return an UpdateManyResult and DatabaseController.update returns { matchedCount, modifiedCount } (or raw adapter result when skipSanitization is true) when options.many is truthy.

Changes

Cohort / File(s) Summary
Bulk Update Tests
spec/DatabaseController.spec.js
Added a Mongo-only describe_only_db('mongo')('update with many', ...) block with tests for update(..., { many: true }) covering: multiple matches, matches with no field changes, no matches, op-based updates, and skipSanitization: true returning raw adapter result (includes extra fields like acknowledged).
Storage Adapter Interface
src/Adapters/Storage/StorageAdapter.js
Added exported UpdateManyResult type ({ matchedCount?: number, modifiedCount?: number }) and changed updateObjectsByQuery(...) return type to `Promise<[any]
Database Controller Implementation
src/Controllers/DatabaseController.js
When options.many is truthy, short-circuits post-update flow to return { matchedCount, modifiedCount } (numbers only if adapter provided them; otherwise undefined), and skips _sanitizeDatabaseResult for the bulk-update path unless skipSanitization is set, in which case the raw adapter result is returned.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(220, 235, 255, 0.5)
    participant Client
    participant DBController as DatabaseController
    participant Adapter as StorageAdapter
    participant Mongo as MongoDB
  end

  Client->>DBController: update(className, query, update, options={ many: true }, ...)
  DBController->>Adapter: updateObjectsByQuery(className, schema, query, update, session)
  Adapter->>Mongo: perform bulk update
  Mongo-->>Adapter: UpdateManyResult (matchedCount, modifiedCount, ...raw)
  Adapter-->>DBController: UpdateManyResult
  alt skipSanitization === true
    DBController-->>Client: raw adapter result (contains acknowledged, matchedCount, modifiedCount, ...)
  else
    DBController-->>Client: { matchedCount?: number, modifiedCount?: number }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a clear summary of changes and test coverage, but lacks the required PR template sections (Issue, Approach, Tasks checklist) that are specified in the repository template. Follow the repository PR template by adding Issue section, Approach section, and completing the Tasks checklist (mark completed items and remove inapplicable ones).
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 (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: extending the storage adapter interface to return matchedCount and modifiedCount from DatabaseController.update with many option.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 29, 2026
@mtrezza mtrezza changed the title feat: Return matchedCount and modifiedCount from DatabaseController.update with many: true feat: Return matchedCount and modifiedCount from DatabaseController.update with many: true Mar 29, 2026
Copy link
Copy Markdown

@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)
src/Controllers/DatabaseController.js (1)

536-542: Clarify the many return contract when skipSanitization is enabled.

On Line 540, the JSDoc describes the default many return shape, but skipSanitization=true (same method signature) returns the raw adapter result instead. Consider documenting that explicitly and mirroring it in README/changelog notes for this feature.

Suggested doc tweak
   /**
    * Updates objects in the database that match the given query.
    * `@param` {Object} options
    * `@param` {boolean} [options.many=false] When true, updates all matching documents
    *   and returns `{ matchedCount, modifiedCount }` where values are numbers if the
    *   storage adapter supports `UpdateManyResult`, or `undefined` otherwise.
+   *   If `skipSanitization` is `true`, returns the raw storage-adapter result.
    */

Based on learnings: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Controllers/DatabaseController.js` around lines 536 - 542, The JSDoc for
DatabaseController.updateObjects (the method that updates objects and documents
the options.many return shape) is incomplete: when called with
skipSanitization=true the method returns the raw storage adapter result rather
than the `{ matchedCount, modifiedCount }` normalized shape. Update the JSDoc
for DatabaseController.updateObjects to explicitly state that when
skipSanitization is true the adapter's raw result is returned (and what that may
look like), and add a brief note to README/changelog describing the behavioral
difference; also adjust or add tests referencing updateObjects to assert both
sanitized and raw return shapes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Controllers/DatabaseController.js`:
- Around line 536-542: The JSDoc for DatabaseController.updateObjects (the
method that updates objects and documents the options.many return shape) is
incomplete: when called with skipSanitization=true the method returns the raw
storage adapter result rather than the `{ matchedCount, modifiedCount }`
normalized shape. Update the JSDoc for DatabaseController.updateObjects to
explicitly state that when skipSanitization is true the adapter's raw result is
returned (and what that may look like), and add a brief note to README/changelog
describing the behavioral difference; also adjust or add tests referencing
updateObjects to assert both sanitized and raw return shapes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32daf36b-bb37-4387-9538-0c5b006aaad3

📥 Commits

Reviewing files that changed from the base of the PR and between f6b1afa and e656a53.

📒 Files selected for processing (2)
  • spec/DatabaseController.spec.js
  • src/Controllers/DatabaseController.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • spec/DatabaseController.spec.js

@mtrezza mtrezza changed the title feat: Return matchedCount and modifiedCount from DatabaseController.update with many: true feat: Extend storage adapter interface to return matchedCount and modifiedCount from DatabaseController.update with many: true Mar 30, 2026
@mtrezza mtrezza changed the title feat: Extend storage adapter interface to return matchedCount and modifiedCount from DatabaseController.update with many: true feat: Extend storage adapter interface to optionally return matched and modified count from DatabaseController.update with many: true Mar 30, 2026
@mtrezza mtrezza changed the title feat: Extend storage adapter interface to optionally return matched and modified count from DatabaseController.update with many: true feat: Extend storage adapter interface to optionally return matchedCount and modifiedCount from DatabaseController.update with many: true Mar 30, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.53%. Comparing base (d5f5128) to head (e656a53).
⚠️ Report is 3 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10353      +/-   ##
==========================================
+ Coverage   92.50%   92.53%   +0.02%     
==========================================
  Files         192      192              
  Lines       16552    16554       +2     
  Branches      231      231              
==========================================
+ Hits        15312    15318       +6     
+ Misses       1218     1214       -4     
  Partials       22       22              

☔ 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.

@mtrezza mtrezza merged commit aea7596 into parse-community:alpha Mar 30, 2026
24 checks passed
parseplatformorg pushed a commit that referenced this pull request Mar 30, 2026
# [9.7.0-alpha.18](9.7.0-alpha.17...9.7.0-alpha.18) (2026-03-30)

### Features

* Extend storage adapter interface to optionally return `matchedCount` and `modifiedCount` from `DatabaseController.update` with `many: true` ([#10353](#10353)) ([aea7596](aea7596))
@parseplatformorg
Copy link
Copy Markdown
Contributor

🎉 This change has been released in version 9.7.0-alpha.18

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 30, 2026
parseplatformorg pushed a commit that referenced this pull request Mar 30, 2026
# [9.7.0](9.6.1...9.7.0) (2026-03-30)

### Bug Fixes

* Auth data exposed via verify password endpoint ([GHSA-wp76-gg32-8258](GHSA-wp76-gg32-8258)) ([#10323](#10323)) ([770be86](770be86))
* Batch login sub-request rate limit uses IP-based keying ([#10349](#10349)) ([63c37c4](63c37c4))
* Cloud Code trigger context vulnerable to prototype pollution ([#10352](#10352)) ([d5f5128](d5f5128))
* Cloud function validator bypass via prototype chain traversal ([GHSA-vpj2-qq7w-5qq6](GHSA-vpj2-qq7w-5qq6)) ([#10342](#10342)) ([dc59e27](dc59e27))
* Duplicate session destruction can cause unhandled promise rejection ([#10319](#10319)) ([92791c1](92791c1))
* GraphQL API endpoint ignores CORS origin restriction ([GHSA-q3p6-g7c4-829c](GHSA-q3p6-g7c4-829c)) ([#10334](#10334)) ([4dd0d3d](4dd0d3d))
* GraphQL complexity validator exponential fragment traversal DoS ([GHSA-mfj6-6p54-m98c](GHSA-mfj6-6p54-m98c)) ([#10344](#10344)) ([f759bda](f759bda))
* LiveQuery protected field leak via shared mutable state across concurrent subscribers ([GHSA-m983-v2ff-wq65](GHSA-m983-v2ff-wq65)) ([#10330](#10330)) ([776c71c](776c71c))
* LiveQuery protected-field guard bypass via array-like logical operator value ([GHSA-mmg8-87c5-jrc2](GHSA-mmg8-87c5-jrc2)) ([#10350](#10350)) ([f63fd1a](f63fd1a))
* Maintenance key blocked from querying protected fields ([#10290](#10290)) ([7c8b213](7c8b213))
* MFA single-use token bypass via concurrent authData login requests ([GHSA-w73w-g5xw-rwhf](GHSA-w73w-g5xw-rwhf)) ([#10326](#10326)) ([e7efbeb](e7efbeb))
* Missing error messages in Parse errors ([#10304](#10304)) ([f128048](f128048))
* Postgres query on non-existent column throws internal server error ([#10308](#10308)) ([c5c4325](c5c4325))
* Session field immutability bypass via falsy-value guard ([GHSA-f6j3-w9v3-cq22](GHSA-f6j3-w9v3-cq22)) ([#10347](#10347)) ([9080296](9080296))

### Features

* Add `protectedFieldsSaveResponseExempt` option to strip protected fields from save responses ([#10289](#10289)) ([4f7cb53](4f7cb53))
* Add `protectedFieldsTriggerExempt` option to exempt Cloud Code triggers from `protectedFields` ([#10288](#10288)) ([1610f98](1610f98))
* Add support for `partialFilterExpression` in MongoDB storage adapter ([#10346](#10346)) ([8dd7bf2](8dd7bf2))
* Extend storage adapter interface to optionally return `matchedCount` and `modifiedCount` from `DatabaseController.update` with `many: true` ([#10353](#10353)) ([aea7596](aea7596))
@parseplatformorg
Copy link
Copy Markdown
Contributor

🎉 This change has been released in version 9.7.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released Released as stable version state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants