summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-03-24 10:19:28 -0400
committerEliot Horowitz <eliot@10gen.com>2010-03-24 10:19:28 -0400
commit2dce721f654c5560c3e5f98948ae132a9d2aea6d (patch)
treec06edb5b3673935cc6f7496f8c5b863289c30164
parent5e78c52f1b03fa2d7079a227285f927b4756c1b2 (diff)
downloadmongo-2dce721f654c5560c3e5f98948ae132a9d2aea6d.tar.gz
$regex handles RegEx
-rw-r--r--db/matcher.cpp8
-rw-r--r--jstests/regex9.js11
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" )