发布于 2015-09-14 15:08:23 | 108 次阅读 | 评论: 0 | 来源: 网络整理

$addToSet

The $addToSet operator adds a value to an array only if the value is not in the array already. If the value is in the array, $addToSet returns without modifying the array. Consider the following example:

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

Here, $addToSet appends value1 to the array stored in field, only if value1 is not already a member of this array.

注解

$addToSet only ensures that there are no duplicate items in a set and makes no guarantees regarding the order of the elements in the set.

See

$each and $push

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

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