Skip to content
Browse files

$pop from an empty fix SERVER-2465

  • Loading branch information...
1 parent 9a397af commit ded0dac9263f9205bbc2efe45537da49210e1c10 @erh erh committed Mar 31, 2011
Showing with 39 additions and 4 deletions.
  1. +5 −2 db/update.cpp
  2. +34 −2 jstests/push.js
View
7 db/update.cpp
@@ -570,13 +570,16 @@ namespace mongo {
switch ( m.m->op ) {
case Mod::UNSET:
- case Mod::PULL:
- case Mod::PULL_ALL:
case Mod::ADDTOSET:
case Mod::RENAME_FROM:
case Mod::RENAME_TO:
// this should have been handled by prepare
break;
+ case Mod::PULL:
+ case Mod::PULL_ALL:
+ case Mod::POP:
+ assert( m.old.eoo() || ( m.old.isABSONObj() && m.old.Obj().isEmpty() ) );
+ break;
// [dm] the BSONElementManipulator statements below are for replication (correct?)
case Mod::INC:
if ( isOnDisk )
View
36 jstests/push.js
@@ -17,6 +17,38 @@ 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" );
+assert.eq( "2,3,4,5" , t.findOne().a.toString() , "E1" );
+
+t.update( { _id : 2 } , { $pop : { a : -1 } } );
+assert.eq( "3,4,5" , t.findOne().a.toString() , "E2" );
+
+t.update( { _id : 2 } , { $pop : { a : -1 } } );
+assert.eq( "4,5" , t.findOne().a.toString() , "E3" );
+
t.update( { _id : 2 } , { $pop : { a : -1 } } );
-assert.eq( "3,4,5" , t.findOne().a.toString() , "D" );
+assert.isnull( db.getLastError() , "E4a" )
+assert.eq( "5" , t.findOne().a.toString() , "E4" );
+
+
+t.update( { _id : 2 } , { $pop : { a : -1 } } );
+assert.isnull( db.getLastError() , "E5a")
+assert.eq( "" , t.findOne().a.toString() , "E5" );
+
+t.update( { _id : 2 } , { $pop : { a : -1 } } );
+assert.isnull( db.getLastError() , "E6a" )
+assert.eq( "" , t.findOne().a.toString() , "E6" );
+
+t.update( { _id : 2 } , { $pop : { a : -1 } } );
+assert.isnull( db.getLastError() , "E7a" )
+assert.eq( "" , t.findOne().a.toString() , "E7" );
+
+t.update( { _id : 2 } , { $pop : { a : 1 } } );
+assert.isnull( db.getLastError() , "E8a" )
+assert.eq( "" , t.findOne().a.toString() , "E8" );
+
+t.update( { _id : 2 } , { $pop : { b : -1 } } );
+assert.isnull( db.getLastError() , "E4a" )
+
+t.update( { _id : 2 } , { $pop : { b : 1 } } );
+assert.isnull( db.getLastError() , "E4a" )
+

0 comments on commit ded0dac

Please sign in to comment.
Something went wrong with that request. Please try again.