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

Using regex with the $and operator on the same field more than once

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Querying
    • None
    • ALL
    • Hide

      I have a simple array of strings within a document, which is indexed, next I do this:

      db.listings.find({ $and: [ {suggestion: /^Mercedes/}, {suggestion: /^Ser/} ] }, { suggestion: 1}).explain()
      

      On the explain I get this:

      "indexBounds" : {
              "suggestion" : [ 
                  [ 
                      "Mercedes", 
                      "Mercedet"
                  ], 
                  [ 
                      /^Mercedes/, 
                      /^Mercedes/
                  ]
              ]
          },
      

      but if I put the $or instead of $and I get this:

       "indexBounds" : {
              "suggestion" : [ 
                  [ 
                      "Mercedes", 
                      "Mercedet"
                  ], 
                  [ 
                      "Ser", 
                      "Ses"
                  ], 
                  [ 
                      /^Mercedes/, 
                      /^Mercedes/
                  ], 
                  [ 
                      /^Ser/, 
                      /^Ser/
                  ]
              ]
          }
      

      Im querying the same document and the same array on both cases

      Show
      I have a simple array of strings within a document, which is indexed, next I do this: db.listings.find({ $and: [ {suggestion: /^Mercedes/}, {suggestion: /^Ser/} ] }, { suggestion: 1}).explain() On the explain I get this: "indexBounds" : { "suggestion" : [ [ "Mercedes", "Mercedet" ], [ /^Mercedes/, /^Mercedes/ ] ] }, but if I put the $or instead of $and I get this: "indexBounds" : { "suggestion" : [ [ "Mercedes", "Mercedet" ], [ "Ser", "Ses" ], [ /^Mercedes/, /^Mercedes/ ], [ /^Ser/, /^Ser/ ] ] } Im querying the same document and the same array on both cases
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Hello,

      not sure if this is an issue, but I didn't found anything useful on the docs...

      can I query same field using regex and $and operator? when I add the explain() I dont see the second regex shown there

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            eriol Eriol Gjergji
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: