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

风格不统一 提交于 2019-12-09 02:15:21

问题


This error happens when I tried to update upsert item: Updating the path 'x' would create a conflict at 'x'


回答1:


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




回答2:


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'



回答3:


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



来源:https://stackoverflow.com/questions/50947772/updating-the-path-x-would-create-a-conflict-at-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!