Increase max regex pattern length to 32k

XMLWordPrintableJSON

    • Query Execution
    • Minor Change
    • ALL
    • v8.2, v8.0, v7.0
    • Hide

      Make a query with a regex pattern longer than 16384.
       
      ```js
      const kMaxRegexPatternLen = 16384 + 1;
      const patternMaxLen = "c".repeat(kMaxRegexPatternLen);
      ```
       
      Run query:
      ```

      { fieldName: \{ "$regex": patternMaxLen}

      }
      ```
       
      Previously, this query ran fine with a limit upwards of 32764 characters.

      Show
      Make a query with a regex pattern longer than 16384.   ```js const kMaxRegexPatternLen = 16384 + 1; const patternMaxLen = "c".repeat(kMaxRegexPatternLen); ```   Run query: ``` { fieldName: \{ "$regex": patternMaxLen} } ```   Previously, this query ran fine with a limit upwards of 32764 characters.
    • QE 2025-12-08, QE 2025-11-24
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      After upgrading our database several of our queries started failing with the error message

      "Regular expression is invalid: pattern string is longer than the limit set by the application"

       

      I've traced the relevant code to these following lines:

       

      https://github.com/mongodb/mongo/blob/739b0b5f8e53f09e916a57d4b45b8f7dbbddb211/src/mongo/util/pcre.cpp#L130

      https://github.com/PCRE2Project/pcre2/blob/master/src/pcre2_compile.c#L10226C24-L10230

       

      So I am fairly confident this problem was introduced with the following commit:

      https://github.com/mongodb/mongo/commit/468f41278b6b30aa602e81010cf7ef7973d97e4d

       

      An option to change this limit via a config option would solve this regression for us.
       

            Assignee:
            Jan Steemann
            Reporter:
            Chris M
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: