Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

look inside indexed arrays for regexes fix for SERVER-2247

  • Loading branch information...
commit 9193ff5d00829dccffc9572eb15a446bd4d2309e 1 parent a3b7bb6
gregs authored
Showing with 29 additions and 1 deletion.
  1. +11 −1 db/matcher.cpp
  2. +18 −0 jstests/geo_regex0.js
View
12 db/matcher.cpp
@@ -820,8 +820,18 @@ namespace mongo {
BSONElementSet s;
if ( !constrainIndexKey_.isEmpty() ) {
BSONElement e = jsobj.getFieldUsingIndexNames(rm.fieldName, constrainIndexKey_);
- if ( !e.eoo() )
+
+ // Should only have keys nested one deep here, for geo-indices
+ // TODO: future indices may nest deeper?
+ if( e.type() == Array ){
+ BSONObjIterator i( e.Obj() );
+ while( i.more() ){
+ s.insert( i.next() );
+ }
+ }
+ else if ( !e.eoo() )
s.insert( e );
+
}
else {
jsobj.getFieldsDotted( rm.fieldName, s );
View
18 jstests/geo_regex0.js
@@ -0,0 +1,18 @@
+// From SERVER-2247
+// Tests to make sure regex works with geo indices
+
+t = db.regex0
+t.drop()
+
+t.ensureIndex( { point : '2d', words : 1 } )
+t.insert( { point : [ 1, 1 ], words : [ 'foo', 'bar' ] } )
+
+regex = { words : /^f/ }
+geo = { point : { $near : [ 1, 1 ] } }
+both = { point : { $near : [ 1, 1 ] }, words : /^f/ }
+
+assert.eq(1, t.find( regex ).count() )
+assert.eq(1, t.find( geo ).count() )
+assert.eq(1, t.find( both ).count() )
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.