Fix nested array element queries - support querying array elements with dot notation#51
Draft
Fix nested array element queries - support querying array elements with dot notation#51
Conversation
…th dot notation Co-authored-by: scottrogowski <466747+scottrogowski@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] @scottrogowski/mongita/issues/44
Fix nested array element queries - support querying array elements with dot notation
Jul 27, 2025
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.
Fixes issue #44 where querying nested array elements using dot notation (e.g.,
results.product) was not working correctly.Problem
When attempting to query documents with arrays of objects using dot notation, Mongita would return no results even when matching documents existed:
Root Cause
The
_get_item_from_docfunction incollection.pywas not designed to handle array element queries. When encountering a path likeresults.productwhereresultsis an array of objects, it would try to accessarray["product"]which fails since arrays don't have named properties.Solution
Enhanced
_get_item_from_docfunction: Modified to detect when a path component is not a numeric array index and the current item is an array. In such cases, it now searches through each array element (if it's an object) and recursively applies the remaining path, returning all matching values as a list.Updated
_doc_matches_aggfunction: Enhanced all query operators ($eq,$ne,$lt,$lte,$gt,$gte,$in,$nin) to properly handle list values returned from nested array queries. For comparison operators, it now checks if ANY element in the array matches the condition (following MongoDB semantics).Changes Made
_get_item_from_docto handle array element queries with dot notation_doc_matches_aggto support all query operators with array element resultstest_nested_array_queriescovering:Verification
The fix now correctly handles the original issue example:
All existing tests continue to pass, ensuring backward compatibility is maintained.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.