{
"_id" : "201",
"shopServiceCategorys" : [
{
"shopServiceCategoryId" : NumberLong(4593138),
"shopid" : NumberLong(201),
"serviceCategoryId" : NumberLong(5),
"status" : 3.0
},
{
"shopServiceCategoryId" : NumberLong(4593139),
"shopid" : NumberLong(201),
"serviceCategoryId" : NumberLong(12),
"status" : 4.0
}
],
}
更新 id=201,shopServiceCategoryId.serviceCategoryId=12 的status值爲0
執行($定位符,可以找到匹配的數組位置,但只更新第一個,怎麼更新所有匹配的):
db.getCollection('shop').update(
{"_id":"201","shopServiceCategorys.serviceCategoryId":12},
{"$set":{"shopServiceCategorys.$.status":0}
}
)