Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

44.7. update

根据query条件修改,如果不存在则插入,允许修改多条记录

			db.foo.update({'yy':5},{'$set':{'xx':2}},upsert=true,multi=true)
		

44.7.1. multi 更新所有数据

update 第一个参数是条件,当不写条件时将匹配所有数据。

			
db.getCollection('certificate').update({},{'$set':{'icon':'52bfbb7d92b3f41da2e4103f1990c054990be863.png'}},upsert=false,multi=true)			
			
			

44.7.2. upsert 更新,如果不存在则插入数据

			
db.getCollection('shippingAddress').update({'memberId':'00000000'},{'$set':{'defaults': false}},upsert=true,multi=true)
			
			

44.7.3. updateMany 更新集合中的所有数据

			
db.getCollection("sfzito_qcc").updateMany( { }, { $set: { 
	"totalInvoiceAmount": NumberInt("24000") 
}})