'Upadating documents not possible due to lack of atomic operators?

I am trying to update my collection through mongodb shell but unsuscessfully due to this error: "Update document requires atomic operators"

db.dogs_main_breed.updateMany([
  {},
  {
    $unwind: "$Behavior"
  },
  {
    $replaceRoot: {
      newRoot: {
        $mergeObjects: [
          "$$ROOT",
          "$Behavior"
        ]
      }
    }
  },
  {
    $project: {
      Behavior: 0
    }
  }
])

How could be possible to update my documents given this query?

My goal is to flatten "Behavior" field and include it in Root directory of my document:

"breed": "Akita",
  "origin": "Japan",
  "url": "https://en.wikipedia.org/wiki/Akita_(dog)",
  "img": "some img url",
  "WikiDescr": [
    {
      "contenido": "Content"
    }
  ],
  "Behavior": [
    {
      "good_with_children": 3,
      "good_with_other_dogs": 1,
    }

Desired output:

"breed": "Akita",
  "origin": "Japan",
  "url": "https://en.wikipedia.org/wiki/Akita_(dog)",
  "img": "some img url",
  "good_with_children": 3,
  "good_with_other_dogs": 1,
  "WikiDescr": [
    {
      "contenido": "Content"
    }
  ],


Solution 1:[1]

Can you try out this query?

db.dogs_main_breed.aggregate([
  {
    '$unwind': '$Behavior'
  }, {
    '$replaceRoot': {
      'newRoot': {
        '$mergeObjects': [
          '$$ROOT', '$Behavior'
        ]
      }
    }
  }, {
    '$project': {
      'Behavior': 0
    }
  }, {
    '$out': 'dogs_main_breed'
  }
])

Here the link of Mongo Playground to try out the query

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HandsomeCoder