发布于 2015-09-14 14:56:59 | 194 次阅读 | 评论: 0 | 来源: 网络整理

$push

The $push operator appends a specified value to an array. For example:

db.collection.update( { field: value }, { $push: { field: value1 } } );

Here, $push appends value1 to the array identified by value in field. Be aware of the following behaviors:

  • If the field specified in the $push statement (e.g. { $push: { field: value1 } }) does not exist in the matched document, the operation adds a new array with the specified field and value (e.g. value1) to the matched document.
  • The operation will fail if the field specified in the $push statement is not an array. $push does not fail when pushing a value to a non-existent field.
  • If value1 is an array itself, $push appends the whole array as an element in the identified array. To add multiple items to an array, use $pushAll.
最新网友评论  共有(0)条评论 发布评论 返回顶部

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