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

44.14. 内嵌对象

44.14.1. Array / List 列表类型

			
db.foo.save(
{
	'name':'neo',
	'address':[{'city':'shenzhen','post':"518000"}, {'city':'heilongjiang','post':"135000"}],
	'phone':["13113668800","13322993040","13266884444"]
}
)
			
			
			
{
    "_id" : ObjectId("5bbefed1b04a8c0d7395d1b5"),
    "name" : "neo",
    "address" : [ 
        {
            "city" : "shenzhen",
            "post" : "518000"
        }, 
        {
            "city" : "heilongjiang",
            "post" : "135000"
        }
    ],
    "phone" : [ 
        "13113668800", 
        "13322993040", 
        "13266884444"
    ]
}	
			
			

删除数组元素

			
db.getCollection('foo').update({"_id":ObjectId("5bbeff40b04a8c0d7395d1b6")},{"$pull":{"phone":"13266884444"}})		
			
			

删除数组中的对象

			
db.getCollection('foo').update({"_id":ObjectId("5bbeff40b04a8c0d7395d1b6")},{"$pull":{"address":{"city":"heilongjiang"}}})
			
			

查找替换

			
db.getCollection('foo').update({"address.city":"shenzhen"},{"$set":{"address.$.post":"000000"}})