diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-12-11 12:33:16 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-12-11 12:33:16 -0500 |
commit | 85799367e759ed309a1103659560799bd37dbcc8 (patch) | |
tree | e0d3eb35caf06ce6fd9ee9e7036773af8e668d42 /jstests | |
parent | b07d09c466e8536a687078d111abd347c292b8d8 (diff) | |
download | mongo-85799367e759ed309a1103659560799bd37dbcc8.tar.gz |
$pull uses a matcher now, so partial matches are supported
and things like { $pull : { a : { x : { $gt : 5 } } } }
SERVER-452
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/pull2.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/jstests/pull2.js b/jstests/pull2.js new file mode 100644 index 00000000000..ca13fc2e726 --- /dev/null +++ b/jstests/pull2.js @@ -0,0 +1,31 @@ + +t = db.pull2; +t.drop(); + +t.save( { a : [ { x : 1 } , { x : 1 , b : 2 } ] } ); +assert.eq( 2 , t.findOne().a.length , "A" ); + +t.update( {} , { $pull : { a : { x : 1 } } } ); +assert.eq( 0 , t.findOne().a.length , "B" ); + +assert.eq( 1 , t.find().count() , "C1" ) + +t.update( {} , { $push : { a : { x : 1 } } } ) +t.update( {} , { $push : { a : { x : 1 , b : 2 } } } ) +assert.eq( 2 , t.findOne().a.length , "C" ); + +t.update( {} , { $pullAll : { a : [ { x : 1 } ] } } ); +assert.eq( 1 , t.findOne().a.length , "D" ); + +t.update( {} , { $push : { a : { x : 2 , b : 2 } } } ) +t.update( {} , { $push : { a : { x : 3 , b : 2 } } } ) +t.update( {} , { $push : { a : { x : 4 , b : 2 } } } ) +assert.eq( 4 , t.findOne().a.length , "E" ); + +assert.eq( 1 , t.find().count() , "C2" ) + + +t.update( {} , { $pull : { a : { x : { $lt : 3 } } } } ); +assert.eq( 2 , t.findOne().a.length , "F" ); +assert.eq( [ 3 , 4 ] , t.findOne().a.map( function(z){ return z.x; } ) , "G" ) + |