Skip to content

Commit

Permalink
look inside indexed arrays for regexes fix for SERVER-2247
Browse files Browse the repository at this point in the history
  • Loading branch information
gregs committed Apr 6, 2011
1 parent a3b7bb6 commit 9193ff5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion db/matcher.cpp
Expand Up @@ -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 );
Expand Down
18 changes: 18 additions & 0 deletions 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() )


0 comments on commit 9193ff5

Please sign in to comment.