summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-05-04 00:44:29 -0400
committerEliot Horowitz <eliot@10gen.com>2010-05-04 00:44:29 -0400
commitfe2d4d93f2599cf2b955e880be2fb64d8dca9097 (patch)
tree5847dd1eb571709f6b165b4c14bd33cf566cd000
parentc76768d3e8e34e781f30e40427259ffe0a1f8176 (diff)
downloadmongo-fe2d4d93f2599cf2b955e880be2fb64d8dca9097.tar.gz
fix array index when empty array SERVER-1082
-rw-r--r--db/index.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/db/index.cpp b/db/index.cpp
index 5ec2658dfec..81c84ff2f99 100644
--- a/db/index.cpp
+++ b/db/index.cpp
@@ -206,6 +206,8 @@ namespace mongo {
break;
}
}
+
+ bool insertArrayNull = false;
if ( allFound ) {
if ( arrElt.eoo() ) {
@@ -231,29 +233,39 @@ namespace mongo {
}
}
else if ( fixed.size() > 1 ){
- // x : [] - need to insert undefined
- BSONObjBuilder b(_sizeTracker);
- for( unsigned j = 0; j < fixed.size(); ++j ) {
- if ( j == arrIdx )
- b.appendUndefined( "" );
- else
- b.appendAs( fixed[ j ], "" );
- }
- keys.insert( b.obj() );
+ insertArrayNull = true;
}
}
} else {
// nonterminal array element to expand, so recurse
assert( !arrElt.eoo() );
BSONObjIterator i( arrElt.embeddedObject() );
- while( i.more() ) {
- BSONElement e = i.next();
- if ( e.type() == Object )
- _getKeys( fieldNames, fixed, e.embeddedObject(), keys );
+ if ( i.more() ){
+ while( i.more() ) {
+ BSONElement e = i.next();
+ if ( e.type() == Object )
+ _getKeys( fieldNames, fixed, e.embeddedObject(), keys );
+ }
+ }
+ else {
+ insertArrayNull = true;
}
}
- }
+
+ if ( insertArrayNull ){
+ // x : [] - need to insert undefined
+ BSONObjBuilder b(_sizeTracker);
+ for( unsigned j = 0; j < fixed.size(); ++j ) {
+ if ( j == arrIdx )
+ b.appendUndefined( "" );
+ else
+ b.appendAs( fixed[ j ], "" );
+ }
+ keys.insert( b.obj() );
+ }
+ }
+
/* Pull out the relevant key objects from obj, so we
can index them. Note that the set is multiple elements
only when it's a "multikey" array.