如何转换 mongo 数据库文档对象的结构

How to convert structure of mongo db document's object

我有一个结构如下的文档:

id:  6229d3fd40bac327243e4ww2
userID: "594e710c-c632-3ae-929a-f13e294ee6ef"
appID: "622994e2b98225609b89affd"
notifications:Object
     6229d3e040bac3272qwe4441: 1  
     622ew3e041bac3272qwe4441: 1

我想将此结构更新为:

id:  6229d3fd40bac327243e4ww2
userID: "594e710c-c632-43ae-929a-f13e294ee6ef"
appID: "622994e2b98225609b89affd"
notifications:Object
     6229d3e040bac3272qwe4441: {a:1, b:false}  
     622ew3e040bac3272qwe4441: {a:1, b:false}

我在迭代 notification 对象字段时遇到问题,因为它是随机的十六进制字符串。 我尝试使用以下解决方案但无法获得预期结果

db.collection.update({},
[
  {
    $set: {
      notifications: {
        $arrayToObject: {
          $map: {
            input: { $objectToArray: "$notifications" },
            as: "n",
            in: {
              k: "$$n.k",
              v: { a: "$$n.v", b: false }
            }
          }
        }
      }
    }
  }
],
{
  multi: true
})

mongoplayground