Skip to content

Fix elemMatch null object array handling#9257

Open
henyanagar wants to merge 1 commit into
apache:masterfrom
henyanagar:fix-elemmatch-null-array
Open

Fix elemMatch null object array handling#9257
henyanagar wants to merge 1 commit into
apache:masterfrom
henyanagar:fix-elemmatch-null-array

Conversation

@henyanagar

@henyanagar henyanagar commented Jun 14, 2026

Copy link
Copy Markdown

Fixes #9103

Summary

This updates $elemMatch handling for arrays that contain both objects and null values.

Previously, $elemMatch decided whether to use rowFilter() based only on the first array element. If the first element was an object, later null entries were still passed into rowFilter(), which could throw a TypeError when resolving nested fields.

The updated logic checks each array element before applying object-field matching, so null entries are ignored for object-field $elemMatch selectors instead of throwing.

Testing

  • Added a regression test for $elemMatch with an object array containing null.
  • Verified the new test fails before the fix with:
    TypeError: Cannot read properties of null
  • Verified after the fix:
    1 passing
  • Verified the full elem-match test file:
    7 passing
  • Ran ESLint on the changed source and test files.

@janl

janl commented Jun 17, 2026

Copy link
Copy Markdown
Member

Hi, thank you for your contribution. Would you be able to use our pull request template, so we can process your submission according to our guidelines? Thank you.

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.

elemMatch throws TypeError: value is null if array has null element

2 participants