update()函数原型
db.collection.update( <query>, <update>, <options> )
例子
| // 如果<update>参数包含字段不存在,update()方法将添加新的字段。
db.test.update(
	{_id:1},
	{
		$set: {'user.first':'fengdingbo.com'}
	}
) | 
// 如果<update>参数包含字段不存在,update()方法将添加新的字段。
db.test.update(
	{_id:1},
	{
		$set: {'user.first':'fengdingbo.com'}
	}
)
| // 删除一个字段
db.test.update(
	{_id:3},
	{
		$unset:{ldate:1}
	}
) | 
// 删除一个字段
db.test.update(
	{_id:3},
	{
		$unset:{ldate:1}
	}
)
| // 累加
db.test.update(
	{_id:3},
	{
		$inc:{age:4}
	}
) | 
// 累加
db.test.update(
	{_id:3},
	{
		$inc:{age:4}
	}
)
| // 给数组添加一个元素
db.test.update(
	{_id:3},
	{
		$push:{
			like:'C'
		}
	}
) | 
// 给数组添加一个元素
db.test.update(
	{_id:3},
	{
		$push:{
			like:'C'
		}
	}
)
| // 更新多条
db.test.update(
	{_id:{$lte:3}},
	{
		$inc:{age:2}
	},
	{multi:true}
) | 
// 更新多条
db.test.update(
	{_id:{$lte:3}},
	{
		$inc:{age:2}
	},
	{multi:true}
)
更新插入upsert
1. 如果查询匹配一个现有的文档,执行更新操作
2. 如果查询匹配集合中没有文档,执行插入操作。
db.collection.update( <query>, <update>, { upsert: true } )
例子
| db.test.update(
	{_id:5},
	{
		user:{first:'qiufeng',last:'fengdingbo.com'},
		age:1,
		birth:Date('Dec 08, 1984'),
		like:['php','perl','python']
	},
	{upsert:true}
) | 
db.test.update(
	{_id:5},
	{
		user:{first:'qiufeng',last:'fengdingbo.com'},
		age:1,
		birth:Date('Dec 08, 1984'),
		like:['php','perl','python']
	},
	{upsert:true}
)
更新插入save()
1. 如果_id存在值5,执行更新操作
2. 如果_id不存在值5,执行插入操作。
| db.test.save(
	{
		_id:10,
		user:{first:'qiufeng',last:'fengdingbo.com'},
		birth:Date('Dec 08, 1984'),
		like:['php','perl','python2']
	}
) | 
db.test.save(
	{
		_id:10,
		user:{first:'qiufeng',last:'fengdingbo.com'},
		birth:Date('Dec 08, 1984'),
		like:['php','perl','python2']
	}
)
官网手册:http://docs.mongodb.org/manual/applications/update/