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

extended options for $regex cannot be displayed in explain output when used on an index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • ALL
    • Hide
      > db.c.insert({a:"asdf"})
      > db.c.find({a:{$regex:"a", $options:"msix"}})
      { "_id" : ObjectId("528a91ff76468672f5307242"), "a" : "asdf" }
      > db.c.ensureIndex({a:1})
      > db.c.find({a:{$regex:"a", $options:"msix"}}).explain()
      Mon Nov 18 22:20:46.260 Error: 16863 Error converting /a/msix in field 0 to a JS RegExp object: SyntaxError: Invalid flags supplied to RegExp constructor 'msix' at src/mongo/shell/types.js:612
      > db.c.find({a:{$regex:"a", $options:"mi"}}).explain()
      {
      	"cursor" : "BtreeCursor a_1 multi",
      	"isMultiKey" : false,
      	"n" : 2,
      	"nscannedObjects" : 2,
      	"nscanned" : 2,
      	"nscannedObjectsAllPlans" : 2,
      	"nscannedAllPlans" : 2,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"a" : [
      			[
      				"",
      				{
      					
      				}
      			],
      			[
      				/a/im,    // js regexes can't handle 's' or 'x' here
      				/a/im
      			]
      		]
      	},
      	"server" : "llmac:27017"
      }
      
      Show
      > db.c.insert({a: "asdf" }) > db.c.find({a:{$regex: "a" , $options: "msix" }}) { "_id" : ObjectId( "528a91ff76468672f5307242" ), "a" : "asdf" } > db.c.ensureIndex({a:1}) > db.c.find({a:{$regex: "a" , $options: "msix" }}).explain() Mon Nov 18 22:20:46.260 Error: 16863 Error converting /a/msix in field 0 to a JS RegExp object: SyntaxError: Invalid flags supplied to RegExp constructor 'msix' at src/mongo/shell/types.js:612 > db.c.find({a:{$regex: "a" , $options: "mi" }}).explain() { "cursor" : "BtreeCursor a_1 multi" , "isMultiKey" : false , "n" : 2, "nscannedObjects" : 2, "nscanned" : 2, "nscannedObjectsAllPlans" : 2, "nscannedAllPlans" : 2, "scanAndOrder" : false , "indexOnly" : false , "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "a" : [ [ "", { } ], [ /a/im, // js regexes can 't handle ' s ' or ' x' here /a/im ] ] }, "server" : "llmac:27017" }

      Using extended $options for $regex (i.e. "x" or "s") does not work with explain output. Instead, we get the following error:

      Error: 16863 Error converting /a/msix in field 0 to a JS RegExp object: SyntaxError: Invalid flags supplied to RegExp constructor 'sx' at src/mongo/shell/types.js:612
      

      It looks like there is an attempt at converting the $regex:... , $options:... format of a mongo regular expression into the javascript /.../ regular expression format when formatting the explain output, but the non-standard flags can't be appended to this.

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            luke.lovett Luke Lovett
            Votes:
            2 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: