MongoDB:在重复键更新时插入 [英] MongoDB: insert on duplicate key update
本文介绍了MongoDB:在重复键更新时插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一个 [atomic] 语句中使用 Mongo 做到这一点:
How can do this with Mongo in one [atomic] statement:
insert mytable set MyUniqueKey = ?, X = ? on duplicate key update Y = ?
第一次执行该语句时,它会设置 X 值,但之后只会更新 Y 值.
When this statement is executed for first time it will set X value but after that it will only update Y value.
只有 MyUniqueKey 是唯一键的一部分,应该查找重复项.
Only MyUniqueKey is part of unique key and should be looked up for duplicates.
推荐答案
我在 mongodb 用户组问过这个问题,答案是不可能的,这是一个开放的 问题.
I asked this question on mongodb user group, the answer was that it is not possible and this is an open issue.
这篇关于MongoDB:在重复键更新时插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文