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

17 lines
525 B
JavaScript
Raw Normal View History

2010-03-08 02:55:14 +01:00
t = db.tilde;
t.drop();
t.insert( { } );
t.insert( { x : [1,2,3] } );
t.insert( { x : 99 } );
2010-03-10 03:24:36 +01:00
t.update( {x : 2}, { $inc : { "x.$" : 1 } } , false, true );
2010-03-08 03:42:58 +01:00
assert( t.findOne({x:1}).x[1] == 3, "A1" );
2010-03-08 02:55:14 +01:00
t.insert( { x : { y : [8,7,6] } } )
2010-03-10 03:24:36 +01:00
t.update( {'x.y' : 7}, { $inc : { "x.y.$" : 1 } } , false, true )
2010-03-08 16:57:45 +01:00
assert.eq( 8 , t.findOne({"x.y" : 8}).x.y[1] , "B1" );
2010-03-08 03:42:58 +01:00
2010-03-08 16:57:45 +01:00
t.insert( { x : [90,91,92], y : ['a', 'b', 'c'] } );
2010-03-10 03:24:36 +01:00
t.update( { x : 92} , { $set : { 'y.$' : 'z' } }, false, true );
2010-03-08 16:57:45 +01:00
assert.eq( 'z', t.findOne({x:92}).y[2], "B2" );