MongoDB - Replace embedded fields

db.collection.aggregate([
  {
    $set: {
      addonGroups: {
        $map: {
          input: "$addonGroups",
          as: "addonGroup",
          in: {
            "$mergeObjects": [
              "$$addonGroup",
              {
                "addons": {
                  $map: {
                    input: "$$addonGroup.addons",
                    as: "addon",
                    in: {
                      $mergeObjects: [
                        "$$addon",
                        {
                          "name": {
                            $replaceAll: {
                              input: "$$addon.name",
                              find: "\t",
                              replacement: " "
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
])
Topics: MongoDB

Related Code Examples