Skip to content

Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#10

Merged
pubkey merged 1 commit into
mainfrom
claude/mongodb-parity-tests
Jul 22, 2026
Merged

Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#10
pubkey merged 1 commit into
mainfrom
claude/mongodb-parity-tests

Conversation

@pubkey

@pubkey pubkey commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Adds test/operators/query/mongodb-parity.test.ts: 18 test cases where every expectation encodes the behavior of a real mongod (verified against MongoDB 7.x via mongodb-memory-server, run side by side with mingo).

Six tests fail by design on current main (7.2.2) — they document divergences from MongoDB, discovered by differential fuzzing while building nosql-query-optimizer:

  1. Regex values inside $in must pattern-match strings (MongoDB $in docs). mingo compares them literally instead:
    • {f: {$in: [/^ab/]}} on {f: 'abc'} → mongod true, mingo false
    • same for mixed lists ([/^a/, 5]) and string elements of array fields
  2. $nin is the exact negation of $in, so it must exclude pattern-matching strings:
    • {f: {$nin: [/^ab/]}} on {f: 'abc'} → mongod false, mingo true
  3. {$elemMatch: {}} matches arrays containing at least one document (object) element:
    • {f: {$elemMatch: {}}} on {f: [{x: 1}]} → mongod true, mingo false
    • scalar-only arrays correctly do not match in either engine

The remaining 12 tests are regression guards for behavior that already agrees with MongoDB and must keep passing after any fix: $eq with a regex operand stays a literal comparison, shorthand regex criteria keep pattern-matching, per-element array matching, type bracketing, and missing-field semantics for $ne/$eq: null.

Suggested fix direction (not included here): extend the shared $in/$nin membership helper so a RegExp list member also tests string values (and string elements of arrays) as a pattern, keeping the existing literal-equality path; make the empty-$elemMatch case match arrays containing a plain-object element.

🤖 Generated with Claude Code

https://claude.ai/code/session_016iwZaQr7eue16AxGWLcA7E


Generated by Claude Code

Every expectation encodes the behavior of a real mongod (verified against
MongoDB 7.x via mongodb-memory-server). Six tests currently fail and
document known divergences:

- a regex list member of $in must pattern-match string values (and string
  elements of array fields); mingo compares it literally instead
- $nin must be the exact negation of $in
- {$elemMatch: {}} must match arrays containing at least one document
  (object) element

The regression-guard section ($eq regex literal comparison, shorthand
regex, per-element array matching, type bracketing, missing-field
semantics) already agrees with MongoDB and must keep passing after a fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016iwZaQr7eue16AxGWLcA7E
@pubkey
pubkey merged commit c2cbe64 into main Jul 22, 2026
0 of 4 checks passed
@pubkey

pubkey commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

kofrasa#613

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.

2 participants