MongoDB更新多重数组字段

数据结构如下:

 1 {
 2     "_id" : ObjectId("5cd915e012d07135645cf8e9"),
 3     "functionPoint" : "xxx",
 4     "domainName" : "xxx",
 5     "statement" : [
 6         {
 7             "name" : "xxx",
 8             "namespace" : "aircondition",
 9             "statementAttributes" : {
10                 "~script" : {
11                     "flag" : 1.0
12                 }
13             }
14         },
15         {
16             "name" : "xxx",
17             "namespace" : "xxx",
18             "statementAttributes" : {
19                 "action" : "off",
20                 "function_name" : "a_c"
21             }
22         }
23     ]
24 }

现在将flag的值变为2

1  db.user.updateMany({
2    'statement.statementAttributes.~script.flag': 1.0
3 }, {
4     $set: {
5  'statement.$.statementAttributes.~script.flag': 2 
7     }
8 })

 

posted @ 2021-11-01 23:35  LightHu  阅读(232)  评论(0)    收藏  举报