From 99b20a0b6b99c9070afe533a65dc1ec3cba4eea9 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Tue, 25 Aug 2009 18:07:30 -0400 Subject: $pop --- jstests/push.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 jstests/push.js (limited to 'jstests/push.js') diff --git a/jstests/push.js b/jstests/push.js new file mode 100644 index 00000000000..2cdd91c35fe --- /dev/null +++ b/jstests/push.js @@ -0,0 +1,22 @@ + +t = db.push +t.drop(); + +t.save( { _id : 2 , a : [ 1 ] } ); +t.update( { _id : 2 } , { $push : { a : 2 } } ); +assert.eq( "1,2" , t.findOne().a.toString() , "A" ); +t.update( { _id : 2 } , { $push : { a : 3 } } ); +assert.eq( "1,2,3" , t.findOne().a.toString() , "B" ); + +t.update( { _id : 2 } , { $pop : { a : 1 } } ); +assert.eq( "1,2" , t.findOne().a.toString() , "C" ); +t.update( { _id : 2 } , { $pop : { a : -1 } } ); +assert.eq( "2" , t.findOne().a.toString() , "D" ); + + +t.update( { _id : 2 } , { $push : { a : 3 } } ); +t.update( { _id : 2 } , { $push : { a : 4 } } ); +t.update( { _id : 2 } , { $push : { a : 5 } } ); +assert.eq( "2,3,4,5" , t.findOne().a.toString() , "D" ); +t.update( { _id : 2 } , { $pop : { a : -1 } } ); +assert.eq( "3,4,5" , t.findOne().a.toString() , "D" ); -- cgit v1.2.1