Skip to content

fix: Handle equivalent MongoDB index conflicts#10502

Open
cyphercodes wants to merge 1 commit into
parse-community:alphafrom
cyphercodes:fix/idempotency-ttl-index-conflict
Open

fix: Handle equivalent MongoDB index conflicts#10502
cyphercodes wants to merge 1 commit into
parse-community:alphafrom
cyphercodes:fix/idempotency-ttl-index-conflict

Conversation

@cyphercodes

@cyphercodes cyphercodes commented Jun 11, 2026

Copy link
Copy Markdown

Pull Request

Issue

Closes #10431

Approach

MongoDB 8.0 can report IndexKeySpecsConflict for the existing _Idempotency TTL index when the only difference is a server-managed index field such as enableOrderedIndex.

This PR updates MongoStorageAdapter.ensureIndex() to handle that error code by loading the existing named index and ignoring the conflict only when the existing index key and stored options are equivalent to the requested index after normalizing server/default fields. Real index conflicts continue to reject.

Tasks

  • Add tests

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced MongoDB storage adapter to gracefully handle index conflicts by accepting equivalent existing indexes and rejecting incompatible ones.
  • Tests

    • Added test coverage for MongoDB index conflict scenarios.

@parse-github-assistant

Copy link
Copy Markdown

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant Bot changed the title fix: handle equivalent MongoDB index conflicts fix: Handle equivalent MongoDB index conflicts Jun 11, 2026
@parse-github-assistant

parse-github-assistant Bot commented Jun 11, 2026

Copy link
Copy Markdown

🚀 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. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1d4d096-a503-465d-8af2-b66380566a17

📥 Commits

Reviewing files that changed from the base of the PR and between 0644675 and 5969034.

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

📝 Walkthrough

Walkthrough

MongoStorageAdapter now gracefully resolves MongoDB's IndexKeySpecsConflict (error code 86) when an existing index is functionally equivalent to the one being created. Internal helpers normalize and compare index options; ensureIndex checks equivalence when conflict occurs and returns successfully if matching, otherwise rethrows. Tests validate both scenarios.

Changes

MongoDB Index Conflict Resolution

Layer / File(s) Summary
Index comparison helpers
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Adds constants for option normalization and helper functions to normalize MongoDB index options (removing irrelevant fields like v, ns) and determine if an existing index is equivalent to a requested index by comparing keys and normalized options.
ensureIndex conflict handling
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Updates ensureIndex to catch error code 86 (IndexKeySpecsConflict); when indexName is provided, it fetches existing indexes and returns indexName if the existing index matches the requested key and normalized options, otherwise rethrows the original error.
Test coverage for conflict resolution
spec/MongoStorageAdapter.spec.js
Two test cases verify that IndexKeySpecsConflict is ignored and the index name returned when an existing index is equivalent, and that the original error is propagated when the existing index differs in key specifications.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • mtrezza
🚥 Pre-merge checks | ✅ 5 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Engage In Review Feedback ❓ Inconclusive No review feedback comments found in git history or repository metadata. Unable to verify engagement with feedback if it exists externally. Verify PR #10502 on GitHub to check for code review comments and determine if user engaged with feedback.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix: handle equivalent MongoDB index conflicts' follows the required prefix format and clearly describes the main change.
Description check ✅ Passed The PR description includes all required sections: Issue (closes #10431), Approach (explains the fix), and Tasks (tests added). The description is complete and well-structured.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #10431 by catching error code 86, loading existing indexes, and ignoring conflicts only when indexes are functionally equivalent.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the MongoDB index conflict issue. New tests and adapter logic match the objectives without extraneous modifications.
Security Check ✅ Passed No security vulnerabilities detected. Code uses hardcoded parameters, properly compares critical index options, employs safe library functions, and validates all semantically important index proper...

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.22.0)

OpenGrep fatal error (exit code 2): [00.11][ERROR]: Error: exception Unix_error: No such file or directory stat spec/MongoStorageAdapter.spec.js
Raised by primitive operation at UTmp.replace_named_pipe_by_regular_file_if_needed in file "libs/commons/UTmp.ml", line 145, characters 8-27
Called from Scan_CLI.replace_target_roots_by_regular_files_where_needed.(fun) in file "src/osemgrep/cli_scan/Scan_CLI.ml", lines 1086-1087, characters 19-65
Called from List_.fast_map in file "libs/commons/List_.ml", line 81, characters 17-20
Called


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.

@cyphercodes cyphercodes changed the title fix: Handle equivalent MongoDB index conflicts fix: handle equivalent MongoDB index conflicts Jun 11, 2026
@parse-github-assistant

Copy link
Copy Markdown

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant Bot changed the title fix: handle equivalent MongoDB index conflicts fix: Handle equivalent MongoDB index conflicts Jun 11, 2026
@cyphercodes cyphercodes changed the title fix: Handle equivalent MongoDB index conflicts fix: handle equivalent MongoDB index conflicts Jun 11, 2026
@parse-github-assistant

Copy link
Copy Markdown

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant Bot changed the title fix: handle equivalent MongoDB index conflicts fix: Handle equivalent MongoDB index conflicts Jun 11, 2026
@parse-github-assistant

Copy link
Copy Markdown

I will reformat the title to use the proper commit message syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexKeySpecsConflict on _Idempotency TTL index prevents startup after Parse Server update (MongoDB 8.0)

1 participant