如何使用增量过程更新对象内部的值 mongodb

how to update the value inside object with increment process mongodb

我有一个文件

    "watched": {
        "1": true,
       "2": true, //should add 3 with true value
    },
   "fans": 4 //should increment by 5 it should be 9

每当我进行更新时,它应该增加键和值并将粉丝增量更新为 5

db.getCollection('movies').updateOne({
    _id: Object_id("60e80c96b9c55e7a01898f5c")
},  { $set: { "watched.3": true} }  },
    { $inc: { fans: 5 } } 
)

它确实更新或增加了如何管理两者

db.collection.update({
  _id: ObjectId("60e80c96b9c55e7a01898f5c"),
  "watched.3": {
    $exists: false
  }
},
{
  $set: {
    "watched.3": true
  },
  $inc: {
    fans: 5
  }
})

mongoplayground