[SERVER-74371] Support arbitrary expressions for 'field' parameter for $getField Created: 24/Feb/23  Updated: 01/Feb/24  Resolved: 03/Oct/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0

Type: New Feature Priority: Major - P3
Reporter: Matthew Chiaravalloti Assignee: Henri Nikku
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by COMPASS-7390 Investigate changes in SERVER-74371: ... Closed
Documented
is documented by DOCS-16471 Investigate changes in SERVER-74371: ... Closed
Gantt Dependency
Related
related to SERVER-67030 `$getField` doesn't work with a dynam... Closed
related to JAVA-5160 Test arbitrary expressions for field ... Backlog
is related to SERVER-81496 Weird shapification behavior for $con... Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-09-04, QO 2023-09-18, QO 2023-10-02, QO 2023-10-16
Participants:

 Description   

The $getField operator only supports expressions that resolve to string literals. This ticket is requesting an expansion to $getField that would support any expressions that resolve to string values. For example,

{ $getField: { field: { $toString: "$num" }, input: "$doc" } }



 Comments   
Comment by Andrea Santi [ 01/Feb/24 ]

I suggest to update the documentation for the preivous versions of Mongodb.

 

The documentation says: "...to a string constant"

It took us several hours to realize that we cannot use $myFieldPath

Comment by Andrea Santi [ 01/Feb/24 ]

I suggest to update the documentation for the preivous versions of Mongodb.

 

The documentation says: "...to a string constant"

It took us several hours to realize that we cannot use $myFieldPath

Comment by Githook User [ 03/Oct/23 ]

Author:

{'name': 'henrinikku', 'email': 'henri.nikku@mongodb.com', 'username': 'henrinikku'}

Message: SERVER-74371 Support arbitrary expressions for 'field' parameter for $getField
Branch: master
https://github.com/mongodb/mongo/commit/da394eee5c65f47c2f0044cff229754d951e4cb6

Comment by Matthew Chiaravalloti [ 14/Mar/23 ]

anton.korshunov@mongodb.com I figured that was exactly the case. I couldn't find the history of why this was rejected since I wasn't sure where to find the original design doc(s) for $getField. Figured I'd file this to find out if either it was already definitively ruled out or if it would be something you'd consider. Sounds like it is off the table! You can definitely close this as Won't Do. Thanks!

Comment by Alya Berciu [ 09/Mar/23 ]

A note for triaging: this change should be quite simple in the code, as this was how the expression was originally implemented (see this line on the original commit).

Might be worth having a follow-up fuzzer ticket to update the grammar to allow arbitrary strings in the field expression as well, if this gets scheduled.

Comment by Kyle Suarez [ 09/Mar/23 ]

I spoke to alya.berciu@mongodb.com about this. During the course of PM-1856, there was a concern that allowing a non-constant input field would make optimization of that query difficult. However, to my knowledge there is not a hard reason that makes it impossible.

Passing this ticket to the Query Optimization team for triage / prioritization.

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