Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56674

Standardize query language to avoid $-prefixes for operator arguments

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 4.4.4
    • Component/s: Query Language
    • None
    • Query Optimization

      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>
        }
      }
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            lamualfa@gmail.com Al Fatih
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: