发布于 2015-09-14 14:54:20 | 105 次阅读 | 评论: 0 | 来源: 网络整理

$pop

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.

1.1 新版功能.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务