summaryrefslogtreecommitdiff
path: root/db/index.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/index.cpp')
-rw-r--r--db/index.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/db/index.cpp b/db/index.cpp
index 5ec2658..6931d93 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,45 @@ 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 {
+ BSONElement e = fixed[j];
+ if ( e.eoo() )
+ b.appendNull( "" );
+ else
+ b.appendAs( e , "" );
+ }
+ }
+ 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.