mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
fix equality matching of emdeded docs with numbers SERVER-853
This commit is contained in:
parent
d8e56af586
commit
c91e3ba456
18
db/jsobj.h
18
db/jsobj.h
@ -529,26 +529,12 @@ namespace mongo {
|
||||
just the value.
|
||||
*/
|
||||
bool valuesEqual(const BSONElement& r) const {
|
||||
switch( type() ) {
|
||||
case NumberLong:
|
||||
return _numberLong() == r.numberLong() && r.isNumber();
|
||||
case NumberDouble:
|
||||
return _numberDouble() == r.number() && r.isNumber();
|
||||
case NumberInt:
|
||||
return _numberInt() == r.numberInt() && r.isNumber();
|
||||
default:
|
||||
;
|
||||
}
|
||||
bool match= valuesize() == r.valuesize() &&
|
||||
memcmp(value(),r.value(),valuesize()) == 0;
|
||||
return match && canonicalType() == r.canonicalType();
|
||||
return woCompare( r , false ) == 0;
|
||||
}
|
||||
|
||||
/** Returns true if elements are equal. */
|
||||
bool operator==(const BSONElement& r) const {
|
||||
if ( strcmp(fieldName(), r.fieldName()) != 0 )
|
||||
return false;
|
||||
return valuesEqual(r);
|
||||
return woCompare( r , true ) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1420,6 +1420,16 @@ namespace JsobjTests {
|
||||
}
|
||||
};
|
||||
|
||||
class EmbeddedNumbers {
|
||||
public:
|
||||
void run(){
|
||||
BSONObj x = BSON( "a" << BSON( "b" << 1 ) );
|
||||
BSONObj y = BSON( "a" << BSON( "b" << 1.0 ) );
|
||||
ASSERT_EQUALS( x , y );
|
||||
ASSERT_EQUALS( 0 , x.woCompare( y ) );
|
||||
}
|
||||
};
|
||||
|
||||
class All : public Suite {
|
||||
public:
|
||||
All() : Suite( "jsobj" ){
|
||||
@ -1510,6 +1520,7 @@ namespace JsobjTests {
|
||||
add< checkForStorageTests >();
|
||||
add< InvalidIDFind >();
|
||||
add< ElementSetTest >();
|
||||
add< EmbeddedNumbers >();
|
||||
}
|
||||
} myall;
|
||||
|
||||
|
@ -96,6 +96,14 @@ namespace MatcherTests {
|
||||
}
|
||||
};
|
||||
|
||||
class MixedNumericEmbedded {
|
||||
public:
|
||||
void run(){
|
||||
Matcher m( BSON( "a" << BSON( "x" << 1 ) ) );
|
||||
ASSERT( m.matches( BSON( "a" << BSON( "x" << 1 ) ) ) );
|
||||
ASSERT( m.matches( BSON( "a" << BSON( "x" << 1.0 ) ) ) );
|
||||
}
|
||||
};
|
||||
|
||||
class Size {
|
||||
public:
|
||||
@ -121,6 +129,7 @@ namespace MatcherTests {
|
||||
add< MixedNumericGt >();
|
||||
add< MixedNumericIN >();
|
||||
add< Size >();
|
||||
add< MixedNumericEmbedded >();
|
||||
}
|
||||
} dball;
|
||||
|
||||
|
@ -485,6 +485,8 @@ namespace QueryTests {
|
||||
const char *ns = "unittests.querytests.NumericEmbedded";
|
||||
client().insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) );
|
||||
ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
|
||||
client().ensureIndex( ns , BSON( "a" << 1 ) );
|
||||
ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
|
||||
}
|
||||
};
|
||||
|
||||
@ -1062,8 +1064,7 @@ namespace QueryTests {
|
||||
add< EmptyFieldSpec >();
|
||||
add< MultiNe >();
|
||||
add< EmbeddedNe >();
|
||||
/* SERVER-853
|
||||
* add< EmbeddedNumericTypes >(); */
|
||||
add< EmbeddedNumericTypes >();
|
||||
add< AutoResetIndexCache >();
|
||||
add< UniqueIndex >();
|
||||
add< UniqueIndexPreexistingData >();
|
||||
|
Loading…
Reference in New Issue
Block a user