通过 spring 数据 mongo 做 db.collection.replaceOne [英] Do db.collection.replaceOne by spring data mongo

查看:86
本文介绍了通过 spring 数据 mongo 做 db.collection.replaceOne的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一次更新中替换 mongo 集合中的整个文档,而不是查询和更新".

I want to replace whole document in mongo collection in one update instead of "query and update".

看来 db.collection.replaceOne可以做这个工作,但我在 MongoOperations.

It seems the db.collection.replaceOne can do this job, but I can't find any api in the MongoOperations.

推荐答案

只需调用 save() on MongoTemplate 其中将使用 UpdateOptions().upsert(true) 调用 replaceOne.

Just call save() on MongoTemplate which will invoke replaceOne with UpdateOptions().upsert(true).

这篇关于通过 spring 数据 mongo 做 db.collection.replaceOne的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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