更新嵌套数组中的特定元素

时间:2018-08-01 19:21:12

标签: mongodb mongoose

我具有以下结构

{
  "_id":"5b609d1a5b4e2c03e512992b", 
  "files_missing":5, 
  "files_rejected":0, 
  "userId":"5afcbbcf26d784ca35fac580", 
  "files":[
           { 
              "status":"sent", 
              "_id":"5b609d1a5b4e2c03e5129930", 
              "fileId":"5afcbad526d784ca35fac576", 
              "urls" [ 
                       { 
                         "_id":"5b60e10114bce7084cebc1da",
                         "file":"/data/5b609d195b4e2c03e512992a.pdf", 
                         "status":"sent"
                       },{ 
                         "_id":"5b60e1ea14bce7084cebc1dd",
                         "file":"/data/5b60e1ea14bce7084cebc1dd.pdf", 
                         "status":"sent"
                       }
                      ]
           }
        ],
  "contactId":"5b609d195b4e2c03e512992a",
  "created_at":"2018-07-31T17:32:10.251Z",
  "updated_at":"2018-07-31T17:32:10.251Z",
  }

我想在url元素之一中更新状态

我尝试过:

db.collection.update({contactId:"5b609d195b4e2c03e512992a", 
'files.urls._id': "5b60e1ea14bce7084cebc1dd"},{$set: 
{'files.urls.$.status': 'rejected'}})

MongoDB版本:3.2.17

0 个答案:

没有答案