0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

arrays match themselves embedded as well SERVER-807

This commit is contained in:
Eliot Horowitz 2010-03-22 17:35:07 -04:00
parent d52baa2858
commit 2b79d806c2
3 changed files with 37 additions and 6 deletions

View File

@ -46,10 +46,10 @@ namespace {
}
}
namespace mongo {
//#define DEBUGMATCHER(x) cout << x << endl;
//#define DEBUGMATCHER(x) cout << x << endl;
#define DEBUGMATCHER(x)
namespace mongo {
class Where {
public:
@ -554,7 +554,7 @@ namespace mongo {
}
return 1;
}
} // end opALL
if ( compareOp == BSONObj::NE )
return matchesNe( fieldName, toMatch, obj, em , details );
@ -672,7 +672,7 @@ namespace mongo {
}
if ( compareOp == BSONObj::Equality && e.woCompare( toMatch ) == 0 ){
if ( compareOp == BSONObj::Equality && e.woCompare( toMatch , false ) == 0 ){
// match an entire array to itself
return 1;
}

31
jstests/array_match1.js Normal file
View File

@ -0,0 +1,31 @@
t = db.array_match1
t.drop();
t.insert( { _id : 1 , a : [ 5 , 5 ] } )
t.insert( { _id : 2 , a : [ 6 , 6 ] } )
t.insert( { _id : 3 , a : [ 5 , 5 ] } )
function test( f , m ){
var q = {};
q[f] = [5,5];
assert.eq( 2 , t.find( q ).itcount() , m + "1" )
q[f] = [6,6];
assert.eq( 1 , t.find( q ).itcount() , m + "2" )
}
test( "a" , "A" );
t.ensureIndex( { a : 1 } )
test( "a" , "B" );
t.drop();
t.insert( { _id : 1 , a : { b : [ 5 , 5 ] } } )
t.insert( { _id : 2 , a : { b : [ 6 , 6 ] } } )
t.insert( { _id : 3 , a : { b : [ 5 , 5 ] } } )
test( "a.b" , "C" );
t.ensureIndex( { a : 1 } )
test( "a.b" , "D" );

View File

@ -44,7 +44,7 @@ doTest = function( n ) {
checkEqual( n + " C" , "a.b" , 5 );
assert.eq( 7, t.find( { 'a.b': { $nin: [ 10 ] } } ).count() , n + " L" );
assert.eq( 8, t.find( { 'a.b': { $nin: [ [ 10, 11 ] ] } } ).count() , n + " M" );
assert.eq( 7, t.find( { 'a.b': { $nin: [ [ 10, 11 ] ] } } ).count() , n + " M" );
assert.eq( 7, t.find( { a: { $nin: [ 11 ] } } ).count() , n + " N" );
t.save( { a: { b: [ 20, 30 ] } } );