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"}})