diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2014-02-19 12:45:53 -0500 |
---|---|---|
committer | Matt Kangas <matt.kangas@mongodb.com> | 2014-03-03 22:54:10 -0500 |
commit | 3660343e0b4627d2fee4afb89b74d32644d16d18 (patch) | |
tree | ffa571e0b73ce56d73c2ae23f458f0db772ef782 /jstests/core/updatea.js | |
parent | 9fae141a1f3fe652fa6002e47722c5ceb051cffb (diff) | |
download | mongo-3660343e0b4627d2fee4afb89b74d32644d16d18.tar.gz |
SERVER-12127 migrate js tests to jscore suite when not related to writes
Migrate js tests starting from j-z.
Include SERVER-12920 Update use_power_of_2.js
Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'jstests/core/updatea.js')
-rw-r--r-- | jstests/core/updatea.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/core/updatea.js b/jstests/core/updatea.js new file mode 100644 index 00000000000..bcf50892420 --- /dev/null +++ b/jstests/core/updatea.js @@ -0,0 +1,68 @@ + +var res; +t = db.updatea; +t.drop(); + +orig = { _id : 1 , a : [ { x : 1 , y : 2 } , { x : 10 , y : 11 } ] } + +res = t.save( orig ) +assert.writeOK(res); + +// SERVER-181 +res = t.update( {} , { $set : { "a.0.x" : 3 } } ) +assert.writeOK(res); +orig.a[0].x = 3; +assert.eq( orig , t.findOne() , "A1" ); + +res = t.update( {} , { $set : { "a.1.z" : 17 } } ) +assert.writeOK(res); +orig.a[1].z = 17; +assert.eq( orig , t.findOne() , "A2" ); + +// SERVER-273 +res = t.update( {} , { $unset : { "a.1.y" : 1 } } ) +assert.writeOK(res); +delete orig.a[1].y +assert.eq( orig , t.findOne() , "A3" ); + +// SERVER-333 +t.drop(); +orig = { _id : 1 , comments : [ { name : "blah" , rate_up : 0 , rate_ups : [] } ] } +res = t.save( orig ); +assert.writeOK(res); + + +res = t.update( {} , { $inc: { "comments.0.rate_up" : 1 } , $push: { "comments.0.rate_ups" : 99 } } ) +assert.writeOK(res); +orig.comments[0].rate_up++; +orig.comments[0].rate_ups.push( 99 ) +assert.eq( orig , t.findOne() , "B1" ) + +t.drop(); +orig = { _id : 1 , a : [] } +for ( i=0; i<12; i++ ) + orig.a.push( i ); + + +res = t.save( orig ); +assert.writeOK(res); +assert.eq( orig , t.findOne() , "C1" ); + +res = t.update( {} , { $inc: { "a.0" : 1 } } ); +assert.writeOK(res); +orig.a[0]++; +assert.eq( orig , t.findOne() , "C2" ); + +res = t.update( {} , { $inc: { "a.10" : 1 } } ); +assert.writeOK(res); +orig.a[10]++; + + +// SERVER-3218 +t.drop() +t.insert({"a":{"c00":1}, 'c':2}) +res = t.update({"c":2}, {'$inc':{'a.c000':1}}) +assert.writeOK(res); + +assert.eq( { "c00" : 1 , "c000" : 1 } , t.findOne().a , "D1" ) + |