Mongo/Mongoose Invalid atomic update value error Mongo/Mongoose Invalid atomic update value error database database

Mongo/Mongoose Invalid atomic update value error


This is probably because the updated object is still a Mongoose object.Try to convert it to a JS object before the findOneAndUpdate

object = object.toString()

And delete any potential ID attribute

delete object._id

Or simply

object = object.toObject();


I had the same problem and it turned out I was using $push incorrectly. I was doing

{$push:thing_to_push}

But it needed to be

{$push:{list_to_push_into:thing_to_push}}


@Magrelo and @plus led me to an answer that worked. Something like:

MyModel.findOneAndUpdate({ section_id: '51e427ac550dabbb0900000d' }, mongooseObject.toObject(), { upsert: true }, function(err, results) {    //...});