MongoDB:插入重复密钥更新 [英] MongoDB: insert on duplicate key update

查看:86
本文介绍了MongoDB:插入重复密钥更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个[原子]语句中使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆