From 6f9636903b855c708271f2dc5c59a4c42d223642 Mon Sep 17 00:00:00 2001 From: Dwight Date: Fri, 21 Nov 2008 14:14:40 -0500 Subject: [PATCH] num --- db/jsobj.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 553e44f03fc..dc908df9ce6 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -315,9 +315,15 @@ int BSONObj::woCompare(const BSONObj& r) const { continue; } - int x = (int) l.type() - (int) r.type(); - if( x != 0 ) - return x; + int lt = (int) l.type(); + int rt = (int) r.type(); + int x = lt - rt; + if( x != 0 ) { + if( (lt==NumberInt&&rt==NumberDouble) || (lt==NumberDouble&&rt==NumberInt) ) + ; + else + return x; + } x = strcmp(l.fieldName(), r.fieldName()); if( x != 0 ) return x; @@ -540,13 +546,17 @@ BSONObj emptyObj((char *) &emptyObject); struct BsonUnitTest : public UnitTest { void run() { - BSONObjBuilder A,B; + BSONObjBuilder A,B,C; A.appendInt("x", 2); B.append("x", 2.0); + C.append("x", 2.1); BSONObj a = A.done(); BSONObj b = B.done(); + BSONObj c = C.done(); assert( !(a==b) ); // comments on operator== - int c = a.woCompare(b); - assert( c == 0 ); + int cmp = a.woCompare(b); + assert( cmp == 0 ); + cmp = a.woCompare(c); + assert( cmp < 0 ); } } bsonut;