diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-03-22 17:35:07 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-03-22 17:35:07 -0400 |
commit | 2b79d806c204fe7b4782df59067921fc22202d24 (patch) | |
tree | cf2cd5b21e2d49be001576ca6764506d6fcf21c5 | |
parent | d52baa2858499d40c8e1374eec29b7a9fd7381c7 (diff) | |
download | mongo-2b79d806c204fe7b4782df59067921fc22202d24.tar.gz |
arrays match themselves embedded as well SERVER-807
-rw-r--r-- | db/matcher.cpp | 10 | ||||
-rw-r--r-- | jstests/array_match1.js | 31 | ||||
-rw-r--r-- | jstests/nin.js | 2 |
3 files changed, 37 insertions, 6 deletions
diff --git a/db/matcher.cpp b/db/matcher.cpp index b2c6c324353..009a7ba27e9 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -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; } diff --git a/jstests/array_match1.js b/jstests/array_match1.js new file mode 100644 index 00000000000..f764fb913b1 --- /dev/null +++ b/jstests/array_match1.js @@ -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" ); diff --git a/jstests/nin.js b/jstests/nin.js index edfc03b7043..06582781591 100644 --- a/jstests/nin.js +++ b/jstests/nin.js @@ -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 ] } } ); |