Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix compount key with array indexing SERVER-279

  • Loading branch information...
commit 3e3dda9c97274dc80a5c65caaf4163a266de6622 1 parent a0d3663
@erh erh authored
Showing with 75 additions and 3 deletions.
  1. +15 −2 db/pdfile.cpp
  2. +59 −0 dbtests/namespacetests.cpp
  3. +1 −1  jstests/multi2.js
View
17 db/pdfile.cpp
@@ -689,11 +689,24 @@ namespace mongo {
} else {
// terminal array element to expand, so generate all keys
BSONObjIterator i( arrElt.embeddedObject() );
- while( i.more() ) {
+ if ( i.more() ){
+ while( i.more() ) {
+ BSONObjBuilder b;
+ for( unsigned j = 0; j < fixed.size(); ++j ) {
+ if ( j == arrIdx )
+ b.appendAs( i.next(), "" );
+ else
+ b.appendAs( fixed[ j ], "" );
+ }
+ keys.insert( b.obj() );
+ }
+ }
+ else if ( fixed.size() > 1 ){
+ // x : [] - need to insert undefined
BSONObjBuilder b;
for( unsigned j = 0; j < fixed.size(); ++j ) {
if ( j == arrIdx )
- b.appendAs( i.next(), "" );
+ b.appendUndefined( "" );
else
b.appendAs( fixed[ j ], "" );
}
View
59 dbtests/namespacetests.cpp
@@ -506,6 +506,63 @@ namespace NamespaceTests {
return aDotB();
}
};
+
+ class EmptyArray : Base {
+ public:
+ void run(){
+ create();
+
+ BSONObjSetDefaultOrder keys;
+ id().getKeysFromObject( fromjson( "{a:[1,2]}" ), keys );
+ checkSize(2, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:[1]}" ), keys );
+ checkSize(1, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:null}" ), keys );
+ checkSize(1, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:[]}" ), keys );
+ checkSize(1, keys );
+ keys.clear();
+ }
+ };
+
+ class MultiEmptyArray : Base {
+ public:
+ void run(){
+ create();
+
+ BSONObjSetDefaultOrder keys;
+ id().getKeysFromObject( fromjson( "{a:1,b:[1,2]}" ), keys );
+ checkSize(2, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:1,b:[1]}" ), keys );
+ checkSize(1, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:1,b:null}" ), keys );
+ cout << "YO : " << *(keys.begin()) << endl;
+ checkSize(1, keys );
+ keys.clear();
+
+ id().getKeysFromObject( fromjson( "{a:1,b:[]}" ), keys );
+ checkSize(1, keys );
+ cout << "YO : " << *(keys.begin()) << endl;
+ ASSERT_EQUALS( NumberDouble , keys.begin()->firstElement().type() );
+ keys.clear();
+ }
+
+ protected:
+ BSONObj key() const {
+ return aAndB();
+ }
+ };
+
} // namespace IndexDetailsTests
@@ -720,6 +777,8 @@ namespace NamespaceTests {
add< IndexDetailsTests::ParallelArraysComplex >();
add< IndexDetailsTests::AlternateMissing >();
add< IndexDetailsTests::MultiComplex >();
+ add< IndexDetailsTests::EmptyArray >();
+ add< IndexDetailsTests::MultiEmptyArray >();
add< IndexDetailsTests::MissingField >();
add< IndexDetailsTests::SubobjectMissing >();
add< IndexDetailsTests::CompoundMissing >();
View
2  jstests/multi2.js
@@ -16,7 +16,7 @@ assert.eq( 1 , t.find( { x : 1 , a : null } ).count() , "B2" );
t.dropIndex( { x : 1 } );
t.ensureIndex( { x : 1 , a : 1 } );
-//assert.eq( 3 , t.find( { x : 1 } ).count() , "C" ); // SERVER-279 / 146
+assert.eq( 3 , t.find( { x : 1 } ).count() , "C" ); // SERVER-279
assert.eq( 4 , t.find().sort( { x : 1 , a : 1 } ).count() , "s2" );
assert.eq( 1 , t.find( { x : 1 , a : null } ).count() , "C2" );
Please sign in to comment.
Something went wrong with that request. Please try again.