diff options
-rw-r--r-- | db/matcher.cpp | 8 | ||||
-rw-r--r-- | jstests/regex9.js | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/db/matcher.cpp b/db/matcher.cpp index 009a7ba27e9..8c904e36638 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -263,7 +263,13 @@ namespace mongo { } case BSONObj::opREGEX:{ uassert( 13032, "can't use $not with $regex, use BSON regex type instead", !isNot ); - regex = fe.valuestrsafe(); + if ( fe.type() == RegEx ){ + regex = fe.regex(); + flags = fe.regexFlags(); + } + else { + regex = fe.valuestrsafe(); + } break; } case BSONObj::opOPTIONS:{ diff --git a/jstests/regex9.js b/jstests/regex9.js new file mode 100644 index 00000000000..559efd9f3cc --- /dev/null +++ b/jstests/regex9.js @@ -0,0 +1,11 @@ + +t = db.regex3; +t.drop(); + +t.insert( { _id : 1 , a : [ "a" , "b" , "c" ] } ) +t.insert( { _id : 2 , a : [ "a" , "b" , "c" , "d" ] } ) +t.insert( { _id : 3 , a : [ "b" , "c" , "d" ] } ) + +assert.eq( 2 , t.find( { a : /a/ } ).itcount() , "A1" ) +assert.eq( 2 , t.find( { a : { $regex : "a" } } ).itcount() , "A2" ) +assert.eq( 2 , t.find( { a : { $regex : /a/ } } ).itcount() , "A3" ) |