[SERVER-56674] Standardize query language to avoid $-prefixes for operator arguments Created: 05/May/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Query Language
Affects Version/s: 4.4.4
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Al Fatih Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

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



 Comments   
Comment by Al Fatih [ 04/Sep/21 ]

To prevent the Breaking Changes, MongoDB can't remove the dollar sign from the operator. I see. Thanks.

Comment by Charlie Swanson [ 11/May/21 ]

Hi lamualfa@gmail.com - I have retitled this ticket to put in what I think is the only way out of this mess. Let me know if it makes sense and if you agree with the new description.

Generated at Thu Feb 08 05:39:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.