[SERVER-28250] Error when an agg pipeline assigns a value to the $$CURRENT builtin variable Created: 08/Mar/17 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Aggregation Framework, Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | David Storch | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | neweng, query-44-grooming | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Assigned Teams: |
Query Optimization
|
||||
| Operating System: | ALL | ||||
| Participants: | |||||
| Description |
|
In expressions such as $let which assign a value to a variable, the aggregation system errors when the variable name conflicts with a system variable or is otherwise illegal:
However, a user can write an agg pipeline which assigns to $$CURRENT. This should not be legal:
We should also consider whether it is correct to expose $$CURRENT to user pipelines at all. Usually $$CURRENT acts as an alias for $$ROOT, but it has a special internal use in the implementation of $redact. Arguably exposing $$CURRENT is a mistake, since its special meaning is an implementation detail for the $redact stage. |
| Comments |
| Comment by Adinoyi Omuya [ 09/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
Haha, of course. Thanks. | |||||||||||||||||||||||||||||||||||||
| Comment by Charlie Swanson [ 09/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
adinoyi.omuya '[' is still not allowed - the brackets were used in the way they are in regexes, to imply that 'a-z' meant a, b, c, ..., x, y, z. To further clarify, the only allowed ascii characters are abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 | |||||||||||||||||||||||||||||||||||||
| Comment by Adinoyi Omuya [ 09/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
Thanks charlie.swanson. I replaced ( with [ and ) with ] but still get the following error:
| |||||||||||||||||||||||||||||||||||||
| Comment by Charlie Swanson [ 09/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
adinoyi.omuya yes, it looks like the parenthesis is banned according to the docs on variable names:
| |||||||||||||||||||||||||||||||||||||
| Comment by Adinoyi Omuya [ 06/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
Should the usage above be illegal? | |||||||||||||||||||||||||||||||||||||
| Comment by Adinoyi Omuya [ 06/Jul/18 ] | |||||||||||||||||||||||||||||||||||||
|
We're also seeing this in pipelines like:
| |||||||||||||||||||||||||||||||||||||
| Comment by David Storch [ 08/Mar/17 ] | |||||||||||||||||||||||||||||||||||||
|
In that case, it would probably be too large of a breaking change to hide $$CURRENT altogether. But despite the linked documentation, it still seems wise to disallow rebinding $$CURRENT to a new value. | |||||||||||||||||||||||||||||||||||||
| Comment by Charlie Swanson [ 08/Mar/17 ] | |||||||||||||||||||||||||||||||||||||
|
As part of this we'd have to clean up the docs: https://docs.mongodb.com/master/meta/aggregation-quick-reference/?_ga=1.209516187.861370249.1405529686#field-path-and-system-variables Also, this courseware makes use of the '$$CURRENT' syntax: https://university.mongodb.com/courses/MongoDB/M034/2016_ondemand_v1/courseware/Chapter_15_New_Aggregation_Operators/585024bbcc1972c8677de430/vertical_710eb212e96a |