Skip to content

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

Open
pubkey wants to merge 4 commits into
kofrasa:mainfrom
pubkey:main
Open

Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#613
pubkey wants to merge 4 commits into
kofrasa:mainfrom
pubkey:main

Conversation

@pubkey

@pubkey pubkey commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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

  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.

Question: Shell we add something to the github actions CI that runs a real mongodb server to ensure exact equal bevahior between mongodb and mingo?

claude and others added 2 commits July 22, 2026 14:05
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
Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch
…empty $elemMatch matches document elements

- $in: a RegExp element of the query array now matches string values
  (and string elements of array fields) as a pattern, in addition to the
  existing equality check for stored regex values. $nin inherits the
  behavior as the exact negation.
- $elemMatch: an empty criteria object now matches arrays containing at
  least one document (object) element instead of comparing elements
  against the empty object literal.

Mirrors the behavior of a real mongod; makes the six failing tests of
test/operators/query/mongodb-parity.test.ts pass. Aggregation $in and
projection $elemMatch have separate implementations and are unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016iwZaQr7eue16AxGWLcA7E
Fix MongoDB parity: regex members of $in/$nin pattern-match strings, empty $elemMatch matches document elements
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.79%. Comparing base (10d07f1) to head (f57d258).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #613      +/-   ##
==========================================
+ Coverage   98.76%   98.79%   +0.02%     
==========================================
  Files         267      267              
  Lines        3651     3658       +7     
  Branches     1011     1014       +3     
==========================================
+ Hits         3606     3614       +8     
  Misses          2        2              
+ Partials       43       42       -1     
Flag Coverage Δ
unittests 98.79% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

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