Skip to content

Fix MongoDB parity: regex members of $in/$nin pattern-match strings, empty $elemMatch matches document elements#11

Merged
pubkey merged 1 commit into
mainfrom
claude/mongodb-parity-fix
Jul 23, 2026
Merged

Fix MongoDB parity: regex members of $in/$nin pattern-match strings, empty $elemMatch matches document elements#11
pubkey merged 1 commit into
mainfrom
claude/mongodb-parity-fix

Conversation

@pubkey

@pubkey pubkey commented Jul 23, 2026

Copy link
Copy Markdown
Owner

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:

  1. $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 (MongoDB $in docs). $nin inherits the behavior automatically as the exact negation.
  2. $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 own Query).

Test results: all 18 parity tests in test/operators/query/mongodb-parity.test.ts now 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

…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
@pubkey
pubkey merged commit f57d258 into main Jul 23, 2026
4 checks passed
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