使用 $set 更新集合对象上的嵌套属性 [英] Updating a nested property on a collection object with $set
本文介绍了使用 $set 更新集合对象上的嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有一组看起来像这样的对象:
If one has a collection of objects that look like this:
{
name:"some name",
dob:"april 4, 1985",
address:{
street:"some street",
city:"some city",
}
}
...可以使用 $set 来更新城市吗?
...can $set be used to update just the city?
推荐答案
这个查询应该为你做:
Collection.update({sel}, {"$set" : {"address.city": "new city"}})
这篇关于使用 $set 更新集合对象上的嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文