Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js MongoDB error: the update operation document must contain atomic operators

The error is: the update operation document must contain atomic operators.

db.get().collection('users').updateOne(query, newvalues, function (err, result) {
    cb(err,result)
  })

I already use the $set operator. I just printed on the console both query and newvalues and i cant find any mistake.

query: { username: 'macarra' }
newvalues: { $set: {name: "Mojo Picon",email: "[email protected]"} }

1 Answers

If you have the object with the new values:

var obj = {
   name: "Mojo Picon",
   email: "[email protected]"
}

to build the newvalues object required by the updateOne method you need to:

var newvalues = {
   $set: obj
}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!