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

Regex query returns incorrect results when index is present

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.8.0-rc1
    • Affects Version/s: 2.4.11, 2.6.3, 2.7.6
    • Component/s: Querying
    • None
    • ALL
    • Hide

      See regex_different_results_with_index.js

      Show
      See regex_different_results_with_index.js

      We've noticed a strange issue where a regex query on a field returns different results, depending on whether there is an index defined on that field or not.

      I've included a JS test file (regex_different_results_with_index.js) which reproduces the issue.

      The regex is left-anchored. Also, an equavilent regex expression (included in JS) works in both cases:

      • /^(a(a|$)|b)/ : works both with and without index
      • /^a(a|$)|^b/ : works without an index, does not work with an index

      Looking at the regex expression, the result without the index (both "aa" and "bb" match) should be the correct one. When the index is present, only "aa" is returned, which is incorrect.

      I have tested this on 2.4.11 and 2.6.3.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            victor.hooi Victor Hooi
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: