标签:monggo 嵌套数组
{
"_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}
}
)
本文出自 “11898338” 博客,谢绝转载!
标签:monggo 嵌套数组
原文地址:http://11908338.blog.51cto.com/11898338/1904489