diff --git a/db/jsobj.cpp b/db/jsobj.cpp index f87071bd4ad..25940356546 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -639,7 +639,9 @@ namespace mongo { if ( ordered ) o = k.next(); if ( l.eoo() ) - return 0; + return r.eoo() ? 0 : -1; + if ( r.eoo() ) + return 1; int x = l.woCompare( r, considerFieldName ); if ( ordered && o.number() < 0 ) diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index 4edd3fff0e8..8ce2a9ab314 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -110,6 +110,14 @@ namespace JsobjTests { } }; + class WoCompareDifferentLength : public Base { + public: + void run() { + ASSERT( BSON( "a" << 1 ).woCompare( BSON( "a" << 1 << "b" << 1 ) ) < 0 ); + ASSERT( BSON( "a" << 1 << "b" << 1 ).woCompare( BSON( "a" << 1 ) ) > 0 ); + } + }; + class WoSortOrder : public Base { public: void run() { @@ -117,7 +125,7 @@ namespace JsobjTests { ASSERT( fromjson( "{a:null}" ).woSortOrder( BSON( "b" << 1 ), BSON( "a" << 1 ) ) == 0 ); } }; - + namespace Validation { class Base { @@ -533,6 +541,7 @@ namespace JsobjTests { add< BSONObjTests::WoCompareEmbeddedObject >(); add< BSONObjTests::WoCompareEmbeddedArray >(); add< BSONObjTests::WoCompareOrdered >(); + add< BSONObjTests::WoCompareDifferentLength >(); add< BSONObjTests::WoSortOrder >(); add< BSONObjTests::Validation::BadType >(); add< BSONObjTests::Validation::EooBeforeEnd >();