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.
|
just the value.
|
||||||
*/
|
*/
|
||||||
bool valuesEqual(const BSONElement& r) const {
|
bool valuesEqual(const BSONElement& r) const {
|
||||||
switch( type() ) {
|
return woCompare( r , false ) == 0;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if elements are equal. */
|
/** Returns true if elements are equal. */
|
||||||
bool operator==(const BSONElement& r) const {
|
bool operator==(const BSONElement& r) const {
|
||||||
if ( strcmp(fieldName(), r.fieldName()) != 0 )
|
return woCompare( r , true ) == 0;
|
||||||
return false;
|
|
||||||
return valuesEqual(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 {
|
class All : public Suite {
|
||||||
public:
|
public:
|
||||||
All() : Suite( "jsobj" ){
|
All() : Suite( "jsobj" ){
|
||||||
@ -1510,6 +1520,7 @@ namespace JsobjTests {
|
|||||||
add< checkForStorageTests >();
|
add< checkForStorageTests >();
|
||||||
add< InvalidIDFind >();
|
add< InvalidIDFind >();
|
||||||
add< ElementSetTest >();
|
add< ElementSetTest >();
|
||||||
|
add< EmbeddedNumbers >();
|
||||||
}
|
}
|
||||||
} myall;
|
} 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 {
|
class Size {
|
||||||
public:
|
public:
|
||||||
@ -121,6 +129,7 @@ namespace MatcherTests {
|
|||||||
add< MixedNumericGt >();
|
add< MixedNumericGt >();
|
||||||
add< MixedNumericIN >();
|
add< MixedNumericIN >();
|
||||||
add< Size >();
|
add< Size >();
|
||||||
|
add< MixedNumericEmbedded >();
|
||||||
}
|
}
|
||||||
} dball;
|
} dball;
|
||||||
|
|
||||||
|
@ -485,6 +485,8 @@ namespace QueryTests {
|
|||||||
const char *ns = "unittests.querytests.NumericEmbedded";
|
const char *ns = "unittests.querytests.NumericEmbedded";
|
||||||
client().insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) );
|
client().insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) );
|
||||||
ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
|
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< EmptyFieldSpec >();
|
||||||
add< MultiNe >();
|
add< MultiNe >();
|
||||||
add< EmbeddedNe >();
|
add< EmbeddedNe >();
|
||||||
/* SERVER-853
|
add< EmbeddedNumericTypes >();
|
||||||
* add< EmbeddedNumericTypes >(); */
|
|
||||||
add< AutoResetIndexCache >();
|
add< AutoResetIndexCache >();
|
||||||
add< UniqueIndex >();
|
add< UniqueIndex >();
|
||||||
add< UniqueIndexPreexistingData >();
|
add< UniqueIndexPreexistingData >();
|
||||||
|
Loading…
Reference in New Issue
Block a user