Updating the path 'x' would create a conflict at 'x'

I had the same problem while performing an update query using PyMongo.
I was trying to do:


> db.people.update( {'name':'lmn'}, { $inc : { 'key1' : 2 }, $set: { 'key1' : 5 }})

Notice that here I'm trying to update the value of key1 from two MongoDB Update Operators.

This basically happens when you try to update the value of a same key with more than one MongoDB Update Operators within the same query.

You can find a list of Update Operators over here


Field should appear either in $set, or in $setOnInsert. Not in both.


If you pass the same key in $set and in $unset when updating an item, you will get that error.

For example:

const body = {
   _id: '47b82d36f33ad21b90'
   name: 'John',
   lastName: 'Smith'
}

MyModel.findByIdAndUpdate(body._id, { $set: body, $unset: {name: 1}})

// Updating the path 'name' would create a conflict at 'name'

Tags:

Upsert

Mongodb