[SERVER-46788] Suggestion: alias $any to $in Created: 11/Mar/20 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Sina Siadat | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||
| Sprint: | Query 2020-09-21, Query 2020-10-05 | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
When reading queries with $in, I find it more appropriate to mentally replace the $in operator with $any. Compare the following two queries which could cause confusion for the developer and lead to silent application bugs:
Note that even when reading an $all query, the developer might use the word "in". For example, I read the $all query above as: "documents whose tags array includes all items in the given array". However, replacing $in with $any, I would read the query as "documents whose tags array includes any item in the given array". This matches the behavior of the $in operator more accurately than the in word "in" the $in operator itself. In fact, the documentation for the $in operator uses the word "any" along with "in" to phrase the description of $in:
Also in the queries Query and Projection Operators documentation:
While $in does make sense on its own, it is easy to confuse the behavior of $in and $all with the current terminology. An alias like $any would clarify the confusion and obviate many bugs and unnecessary printf debugging for the developers.
|
| Comments |
| Comment by Katya Kamenieva [ 18/Aug/20 ] | |||
|
Hi siadat@gmail.com, thank you for bringing this up. Although this update is not currently scheduled, we will consider your suggestion when working on the usability improvements of the query language to make sure everything is consistent. | |||
| Comment by Carl Champain (Inactive) [ 11/Mar/20 ] | |||
|
Hi siadat@gmail.com, Thanks for taking the time to submit this report! Kind regards, | |||
| Comment by Sina Siadat [ 11/Mar/20 ] | |||
|
Furthermore, the proposed operator name is consistent with both scalar as well as array fields.
And for the sake of completeness:
Note that all of three lines is read using "in". What distinguishes them are the words "any" and "all". |