Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#613
Open
pubkey wants to merge 4 commits into
Open
Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#613pubkey wants to merge 4 commits into
pubkey wants to merge 4 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).$inmust pattern-match strings (MongoDB$indocs). mingo compares them literally instead:{f: {$in: [/^ab/]}}on{f: 'abc'}→ mongodtrue, mingofalse[/^a/, 5]) and string elements of array fields$ninis the exact negation of$in, so it must exclude pattern-matching strings:{f: {$nin: [/^ab/]}}on{f: 'abc'}→ mongodfalse, mingotrue{$elemMatch: {}}matches arrays containing at least one document (object) element:{f: {$elemMatch: {}}}on{f: [{x: 1}]}→ mongodtrue, mingofalseThe remaining 12 tests are regression guards for behavior that already agrees with MongoDB and must keep passing after any fix:
$eqwith 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/$ninmembership 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-$elemMatchcase 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?