1

私はこの文書構造を持っています

{
    "_id": <OBJECT_ID>,
    "orders": [
         {
              "userId": 1,
              "handleName": "John Doe",
              "orderAmount": 3,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "John Doe"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 2,
              "handleName": "Maria Gigante",
              "orderAmount": 2,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "John Doe"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 1,
              "handleName": "John Doe",
              "orderAmount": 4,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "John Doe"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 3,
              "handleName": "John Doe",
              "orderAmount": 4,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "John Doe"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         }
    ]
}

userIdof1handleNameofを持つすべてのオブジェクトを更新したいと思いますJohn Doe。オブジェクトのハンドル名は同じでも、ユーザー ID が異なる場合があることに注意してください。userIdそのため、最初のものと一致させる必要があります。

たとえば、ハンドル名をに変更したいDonald Stark

私はこの結果を望んでいます:

{
    "_id": <OBJECT_ID>,
    "orders": [
         {
              "userId": 1,
              "handleName": "Donald Stark",
              "orderAmount": 3,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "Donald Stark"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 2,
              "handleName": "Maria Gigante",
              "orderAmount": 2,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "Donald Stark"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 1,
              "handleName": "Donald Stark",
              "orderAmount": 4,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "Donald Stark"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         },
         {
              "userId": 3,
              "handleName": "John Doe",
              "orderAmount": 4,
              "others": [
                   {
                        "userId": 1,
                        "handleName": "Donald Stark"
                   },
                   {
                        "userId": 2,
                        "handleName": "Maria Gigante"
                   }
              ]
         }
    ]
}

これはどのように達成されますか?

更新:更新したい別の内部配列もあるのを忘れていました。

4

2 に答える 2