diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-09-24 15:40:59 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-09-24 15:40:59 -0400 |
commit | 0d8b5981ff7a3df062cfa5839e292718b61911c2 (patch) | |
tree | 76e8051d2522eac10f5b480035a61b89e0b02849 | |
parent | f8da5e06860a0d5e0fd7b5637fcc748127cfbcc3 (diff) | |
download | mongo-0d8b5981ff7a3df062cfa5839e292718b61911c2.tar.gz |
fix pull with primitives and $ops SERVER-1697
-rw-r--r-- | db/update.cpp | 3 | ||||
-rw-r--r-- | db/update.h | 14 | ||||
-rw-r--r-- | jstests/pull_remove1.js | 2 |
3 files changed, 16 insertions, 3 deletions
diff --git a/db/update.cpp b/db/update.cpp index 7891b329048..a59387d860e 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -40,6 +40,9 @@ namespace mongo { // if elt isn't an object, then comparison will work return toMatch.woCompare( elt , false ) == 0; } + + if ( matcherOnPrimitive ) + return matcher->matches( toMatch.wrap( "" ) ); if ( toMatch.type() != Object ){ // looking for an object, so this can't match diff --git a/db/update.h b/db/update.h index b7950de7306..eeec3d2460d 100644 --- a/db/update.h +++ b/db/update.h @@ -43,12 +43,22 @@ namespace mongo { BSONElement elt; // x:5 note: this is the actual element from the updateobj boost::shared_ptr<Matcher> matcher; + bool matcherOnPrimitive; void init( Op o , BSONElement& e ){ op = o; elt = e; - if ( op == PULL && e.type() == Object ) - matcher.reset( new Matcher( e.embeddedObject() ) ); + if ( op == PULL && e.type() == Object ){ + BSONObj t = e.embeddedObject(); + if ( t.firstElement().getGtLtOp() == 0 ){ + matcher.reset( new Matcher( t ) ); + matcherOnPrimitive = false; + } + else { + matcher.reset( new Matcher( BSON( "" << t ) ) ); + matcherOnPrimitive = true; + } + } } void setFieldName( const char * s ){ diff --git a/jstests/pull_remove1.js b/jstests/pull_remove1.js index af4f28f1ff2..379f3f2832b 100644 --- a/jstests/pull_remove1.js +++ b/jstests/pull_remove1.js @@ -10,5 +10,5 @@ assert.eq( o , t.findOne() , "A1" ) o.a = o.a.filter( function(z){ return z >= 6; } ) t.update( {} , { $pull : { a : { $lt : 6 } } } ) -//assert.eq( o.a , t.findOne().a , "A2" ) +assert.eq( o.a , t.findOne().a , "A2" ) |