MongoDB 批量更新和删除字段

MongoDB About 401 words

批量更新

db.getCollection('order').update(
    {account_id:'abcd'},
    {$set:{account_id:'edgh'}},
    {multi:true}
)

删除字段

$unset表示删除指定指端,可以是1或者0或者true

db.getCollection('order').update(
    {account_id:'abcd'},
    {$unset:{account_id:1}},
    {multi:true}
)

注意

下面语句会将整条记录替换为只保留了account_id和主键_id。慎用。

db.getCollection('order').update(
    {account_id:'abcd'},
    {account_id:'edgh'},
    {multi:true}
)
Views: 3,830 · Posted: 2020-11-20

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh