summaryrefslogtreecommitdiff
path: root/jstests/push.js
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-08-25 18:07:30 -0400
committerEliot Horowitz <eliot@10gen.com>2009-08-25 18:07:30 -0400
commit99b20a0b6b99c9070afe533a65dc1ec3cba4eea9 (patch)
treebdf3052a79653f4a33cc55157dab67157e10184d /jstests/push.js
parent358b5e638c44a234a3d40f653e99f925bde852b6 (diff)
downloadmongo-99b20a0b6b99c9070afe533a65dc1ec3cba4eea9.tar.gz
$pop
Diffstat (limited to 'jstests/push.js')
-rw-r--r--jstests/push.js22
1 files changed, 22 insertions, 0 deletions
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" );