pymongo 更新嵌套数据键

pymongo update nested data key

pymongo 查询

    mycol.update(
        {
            "unique_report_id": 330665,
            "structure.name": "sommememe",
            "structure.values.unique_report_name": "areatest"
        },
        {
            "$set": {
                    "structure.$.values.$.report_data": {
                        data
                }
            }
        },
        {
            "multi": True
        }
    )

数据

[
    {
        "structure": [
            {
                "name": "sommememe",
                "values": [
                {
                    "report_name": "area test",
                    "report_heading": "area test",
                    "background": "#f0f2f5",
                    "grid": false,
                    "report_data": {
                    "slslsllsls": {
                        "datasource": "alias",
                        "source": "3",
                        "title": "slslsllsls",
                        "chartColor": "#00D88A",
                        "area": {
                        "x": 10,
                        "y": 10,
                        "width": 360,
                        "height": 360
                        }
                    }
                    },
                    "unique_report_name": "areatest"
                }
                ],
                "type": 1
            }
        ],
        "unique_report_id": 330665
    }
]

我想用来自 api 的数据替换 report_data 键 我正在尝试上面的查询,但它不起作用,

请看看我该如何解决。

谢谢

我又添加了数据。请检查

    Traceback (most recent call last):
    File "/Users/soubhagyapradhan/Desktop/upwork/report/backend/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
        response = get_response(request)
    File "/Users/soubhagyapradhan/Desktop/upwork/report/backend/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/Users/soubhagyapradhan/Desktop/upwork/report/backend/api/views.py", line 314, in create_report
        "structure.$.values.$.report_data": {
    TypeError: unhashable type: 'dict'

当我在 pymongo 上 运行 上面的查询时出现上面的错误。 请检查这里有什么问题。

db.collection.update({
  "structure.values.unique_report_name": "areatest"
},
{
  "$set": {
    "structure.$[].values.$[ele].report_data": {
      "slslsllsls": {
        "datasource": "aliasqqqqqq",
        "source": "3333333",
        "title": "slslsllslsqqqqqq",
        "chartColor": "#00D88A",
        "area": {
          "x": 10000,
          "y": 10000,
          "width": 9999,
          "height": 9999
        }
      }
    }
  }
},
{
  arrayFilters: [
    {
      "ele.unique_report_name": "areatest"
    }
  ]
})

mongoplayground