[SERVER-71836] Verify and fix documentToBsonWithPaths() issues Created: 05/Dec/22  Updated: 11/Dec/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Romans Kasperovics Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File BM-balanced-tree.png     PNG File BM-line-tree.png     Text File diff.patch    
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Sprint: QE 2022-12-26, QE 2023-01-09, QE 2023-07-10, QE 2023-07-24, QE 2023-08-07, QE 2023-08-21, QE 2023-09-04, QE 2023-09-18, QE 2023-10-02, QE 2023-10-16, QE 2023-10-30, QE 2023-11-13, QE 2023-11-27, QE 2023-12-11
Participants:

 Description   

documentToBsonWithPaths() might not be working correctly. It is supposed to return only the parts of a document, but apparently returns more than requested (complete first-level fields), fearing the path semantics for arrays.

For instance, having document x = {a: {b: 13, c: 14}} and calling documentToBsonWithPaths(x, "a.b") on x would return {a: {b: 13, c: 14}}.



 Comments   
Comment by Victor Ghita (Inactive) [ 03/Jul/23 ]

I have talked to david.storch@mongodb.com, and he suspects he didn't want to deal with full-blown arrays and the implementation was intentional (https://github.com/mongodb/mongo/blob/da006e938e12bd81f1fc2a6a5a86b7b177dfe66f/src/mongo/db/pipeline/document_path_support.cpp#L153-L154).
romans.kasperovics@mongodb.com, could you provide some context on making this change?

Comment by Bernard Gorman [ 25/Apr/23 ]

Quick note: we do have a document_path_support helper which is capable of traversing array indices in fields paths much as a MatchExpression does. We may be able to employ this for documentToBsonWithPaths. But we should first confirm that the reason for the existing, highly conservative behaviour is actually related to array traversal, and not some other factor (e.g. the complexity of correctly materializing subdocuments and subarrays in the extracted BSONObj in the case of deep paths).

Generated at Thu Feb 08 06:20:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.