This version of the manual is no longer supported.



The $pop operator removes the first or last element of an array. Pass $pop a value of 1 to remove the last element in an array and a value of -1 to remove the first element of an array. Consider the following syntax:

db.collection.update( {field: value }, { $pop: { field: 1 } } );

This operation removes the last item of the array in field in the document that matches the query statement { field: value }. The following example removes the first item of the same array:

db.collection.update( {field: value }, { $pop: { field: -1 } } );

Be aware of the following $pop behaviors:

  • The $pop operation fails if field is not an array.
  • $pop will successfully remove the last item in an array. field will then hold an empty array.

New in version 1.1.

←   $isolated $ (update)  →