Fix MongoDB parity: regex members of $in/$nin pattern-match strings, empty $elemMatch matches document elements#11
Merged
Conversation
…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
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.
Implements the fixes for the divergences pinned by the parity tests merged in #10, turning
main's CI green again. Mirrors the fork-local equivalent of the upstream fix (kofrasa#613).Two changes in
src/operators/_predicates.ts:$in— aRegExpelement 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 (MongoDB$indocs).$nininherits the behavior automatically as the exact negation.$elemMatch— an empty criteria object now matches arrays containing at least one document (object) element, instead of comparing elements for equality against the empty object literal.Not touched, verified independent: the aggregation-expression
$in(own literal-equality implementation, MongoDB does not pattern-match there) and the projection$elemMatch(builds its ownQuery).Test results: all 18 parity tests in
test/operators/query/mongodb-parity.test.tsnow pass, and the full suite is green — 166 test files, 1902 tests, 0 failures (no regressions, including the guards for$eq-regex literal comparison and$in: [null, ...]missing-field matching).🤖 Generated with Claude Code
https://claude.ai/code/session_016iwZaQr7eue16AxGWLcA7E
Generated by Claude Code