首页 > 代码库 > monggo 嵌套数组操作
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 嵌套数组操作