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

In-query functions incorrectly process regexes nested in arrays

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL

      Between 7.0 and 8.0, the behavior of queries containing components like

      {$documents: {$function: {body: function (arg) {return arg;}, args: [ array: [ /regex with an escaped \/ character/ ] ], land: "js" } } }
      

      changed when sent through OpMsgRequest. In 7.0, the \/ is output correctly, but in 8.0, the \/ becomes a
      /
      (the escaping backslash is itself escaped). This does not occur in 8.0 without the nesting, e.g.

      {$documents: {$function: {body: function (arg) {return arg;}, args: [ regex: /regex with an escaped \/ character/ ] ], land: "js" } } }
      

      or

      {$documents: [ { array: [ /regex with an escaped \/ character/ ] } ] }
      

      Further investigation reveals that, compared to using mongosh, the received queries differ. The mongosh query sends an escaped two-character \/ substring, whereas the OpMsgRequest query sends a one-character / substring.

      Fully reproducing this behavior will likely rewrite writing a test or toy program of some sort in 7.0 to send the right kind of query and observing the received query on the other side.

      Given that $function is deprecated, it's likely that this is not altogether terribly important – or it might even be fixed by SERVER-98936.

            Assignee:
            Unassigned Unassigned
            Reporter:
            william.qian@mongodb.com William Qian
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: