diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-07-23 10:40:37 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-07-23 10:40:37 -0400 |
commit | 502e762508941c67b0047326928d896f54567e3e (patch) | |
tree | 1245cbd25eace91859192927b2b2a662cf8ae9af /jstests/update6.js | |
parent | ae994ff284fdd15c1d4c8240cdd16bc6fecf7114 (diff) | |
download | mongo-502e762508941c67b0047326928d896f54567e3e.tar.gz |
weird $inc issue adding a field
Diffstat (limited to 'jstests/update6.js')
-rw-r--r-- | jstests/update6.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/jstests/update6.js b/jstests/update6.js new file mode 100644 index 00000000000..174fd91fe86 --- /dev/null +++ b/jstests/update6.js @@ -0,0 +1,44 @@ + +t = db.update6; +t.drop(); + +t.save( { a : 1 , b : { c : 1 , d : 1 } } ); + +t.update( { a : 1 } , { $inc : { "b.c" : 1 } } ); +assert.eq( 2 , t.findOne().b.c , "A" ); +assert.eq( "c,d" , t.findOne().b.keySet().toString() , "B" ); + +t.update( { a : 1 } , { $inc : { "b.0e" : 1 } } ); +assert.eq( 1 , t.findOne().b["0e"] , "C" ); +assert.eq( "0e,c,d" , t.findOne().b.keySet().toString() , "D" ); + +// ----- + +t.drop(); + +t.save( {"_id" : 2 , + "b3" : {"0720" : 5 , "0721" : 12 , "0722" : 11 , "0723" : 3 , "0721" : 12} , + //"b323" : {"0720" : 1} , + } + ); + + +assert.eq( 4 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 1 : ks before" ); +t.update({_id:2},{$inc: { 'b3.0719' : 1}},true) +assert.eq( 5 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 1 : ks after" ); + + +// ----- + +t.drop(); + +t.save( {"_id" : 2 , + "b3" : {"0720" : 5 , "0721" : 12 , "0722" : 11 , "0723" : 3 , "0721" : 12} , + "b323" : {"0720" : 1} , + } + ); + + +assert.eq( 4 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 2 : ks before" ); +t.update({_id:2},{$inc: { 'b3.0719' : 1}},true) +//assert.eq( 5 , t.find({_id:2},{b3:1})[0].b3.keySet().length , "test 2 : ks after" ); |