[Array]
role:[type:String]
db.collection.update(
{ <query selector> },
{ $addToSet: { <field1>: <value1>, ... } }
)
db.member.update({_id:ObjectId('594200a1167b4102894b11c0')},{$addToSet:{"role":'VIP'}})
db.collection.update(
{ <query selector> },
{ $addToSet: { <field>: {$each:[ <value1>, <value2>, ... ]} } }
)
db.collection.update(
{ <query selector> },
{ $push: { <field1>: <value1>, ... }}
)
db.collection.update(
{ <query selector> },
{ $push: { <field>: {$each:[ <value1>, <value2>, ... ]} } }
)
db.collection.update(
{ <query selector> },
{ $pushAll: { <field>: [ <value1>, <value2>, ... ] } }
)
db.collection.update(
{ <query selector> },
{
$push: {
<field>: {
$each: [ <value1>, <value2>, ... ],
$position: <num>
}
}
})
db.collection.update(
{ <query selector> },
{ $pull: { <field1>: <value1>, ... } }
)
db.member.update({_id:ObjectId('594200a1167b4102894b11c0')},{$pull:{"role":'VIP'}})
db.collection.update(
{ <query selector> },
{ $pullAll: { <field1>: [ <value1>, <value2> ... ], ... } }
)
db.collection.update(
{ <query selector> },
{ $pop: { <field>: <-1 | 1>, ... } }
)
1:左边第一位/-1:右边第一位
db.collection.update(
{ <array>: value ... },
{ <update operator>: { "<array>.$" : value } }
)
db.member.update({_id:ObjectId('594200a1167b4102894b11c0'),'role':'VIP'},{$set:{"role.$":'System'}})
db.collection.update(
{ <array>: value ... },
{
$push: {
<field>: {
$each: [ <value1>, <value2>, ... ],
$slice: <num>
}
}
})
num:正数表示从头部(左边)开始,负数表示从尾部(右边)开始
[{Object}]
//修改
db.collection.update(
{ <query selector> },
{ $set: { "array.$.field" : value } }
)
//添加
db.member.update({_id:ObjectId('594200a1167b4102894b11c0')},{$set:{"oAuth.weibo":'QQId'}},{upsert:true})