Details
-
Improvement
-
Resolution: Unresolved
-
Trivial - P5
-
None
-
4.4.4
-
None
-
Query Optimization
Description
In some of our oldest query operators, the arguments to the operators start with dollar symbols ($). For example:
{
|
$text:
|
{
|
$search: <string>,
|
$language: <string>,
|
$caseSensitive: <boolean>,
|
$diacriticSensitive: <boolean>
|
}
|
}
|
or
{
|
$regex: {
|
$pattern: <regex>,
|
$options: <options>
|
}
|
}
|
In most (hopefully all) new language additions, we use a dollar ($) prefix for the operator name, but we do not use a dollar for the arguments to the operator. For example:
{
|
$function: {
|
body: <code>,
|
args: <array expression>,
|
lang: "js"
|
}
|
}
|
For the sake of consistency, we should allow the arguments to be provided without the dollar in all the old/existing places. To preserve backwards compatibility we would still support the $-prefix options, but we could deprecate those and encourage migration to the new format.
I hope there are no cases where the grammar would become ambiguous with such a change, but it is worth noting.
Original Title: Inconsistency query format
Original Description
1. The use of $ symbol
in $text operator, MongoDB use $ sign as a prefix for each options. But, why MongoDB doesn't use $ sign for a prefix of $function operator options?
$text
{
|
$text:
|
{
|
$search: <string>,
|
$language: <string>,
|
$caseSensitive: <boolean>,
|
$diacriticSensitive: <boolean>
|
}
|
}
|
$function
{
|
$function: {
|
body: <code>,
|
args: <array expression>,
|
lang: "js"
|
}
|
}
|
as seen, body, args and lang options does not use $ sign in their prefix. to improve consistency, $ sign should be used for these options ($body, $args and $lang).
2. The use of $options operator
Why only $regex operator use that option? Why are the two not combined into one like:
{
|
$regex: {
|
$pattern: <regex>,
|
$options: <options>
|
}
|
}
|