Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-801

Create option to not compile BSON regular expressions to Java Pattern

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: None
    • Component/s: Codecs
    • None

      The Java driver can retrieve Regex-type BSON values from MongoDB under several circumstances:

      • When a regex has been stored in a document, then queried
      • When a regex query is in progress on another connection and the driver queries $cmd.sys.inprog
      • When a regex query is stored in system.profile and the driver queries the profile

      These regexes might be intended by their authors to be PCRE because they're intended to run on server. However, they need not always be. We can't make any predictions about the content of a BSON regex or what its author intended it to match.

      But the Java driver compiled BSON regexes into java.util.Pattern using Pattern.compile. If a regex can't be compiled, then the whole document is unparsable and there's no workaround. Even if the regex is parsable, we don't know if it will behave as intended, since we don't know if java.util.Pattern matches the flavor the regex's author intended it to run on.

      Finally, it's not likely that most regexes retrieved from the server are ever executed client-side, so greedily compiling all regexes is wasteful.

      We should add a way to optionally disable compilation. If compilation is disabled, represent the BSON regexes some other way, e.g. a MongoRegex class that contains the uncompiled regex pattern as a string plus its options.

      Additionally, add a means of sending a PCRE to the server even if its pattern can't be compiled by Pattern, and/or its flags aren't supported by the Pattern.

      With the new API, disable auto-compilation by default, with the option to turn it back on.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: