Spring Data和MongoDB,插入或更新 [英] Spring Data and MongoDB, insert or update

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

问题描述

我正在将Spring Data与MongoDB结合使用.是否可以对我的对象执行诸如插入或更新之类的操作.我正在使用MongoTemplate和MongoOperation类. 非常感谢!

I am using Spring Data with MongoDB. Is it possible to do something like insert or update for my objects. I am using MongoTemplate and MongoOperation classes. Thanks a lot!

推荐答案

在MongoDB中,您可以插入更新

In MongoDB you can insert, update and upsert documents.

"Upsert消除了执行更新或插入操作之前执行单独的数据库调用以检查记录是否存在的需要."

用简单的话来说,可以认为是如果且仅当该文档尚不存在,请继续为我制作"

In simpler terms, this can be thought of "If and only if this document does not exist already, go ahead and make it for me"

应该注意的是,除非您将upsert设置为true,否则upsert将 NOT 不会发生,例如本示例中的

It should be noted that an upsert will NOT happen unless you have set upsert to be true, like in this example from here

db.collection.update( <query>,
                  <update>,
                  { upsert: true } )

这篇关于Spring Data和MongoDB,插入或更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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