Add MongoDB parity tests for $in/$nin regex members and empty $elemMatch#10
Merged
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
Owner
Author
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).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:$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.🤖 Generated with Claude Code
https://claude.ai/code/session_016iwZaQr7eue16AxGWLcA7E
Generated by Claude Code