Java MongoDB一次保存多个文档 [英] Java MongoDB save multiple documents at once
问题描述
我有一个更新的对象/文档列表,我需要一次将所有对象保存在列表中.
I Have a list of updated objects/documents i need save all the objects in the list at once.
我在MongoTemplate中看到了save(),但一次只能处理一个文档. 有没有办法一次保存多个文档,或者我需要调用save in loop吗?
I saw save() in MongoTemplate but it can take single document at a time. Is there any way to save multiple documents at once or i need to call save in loop ?
推荐答案
感谢所有帮助.
我能够使用Spring数据MongoDB做到这一点. 春季数据MongoDB的MongoRepository具有许多内置方法.
I was able to do it using Spring data MongoDB. Spring data MongoDB's MongoRepository has many inbuilt methods.
org.springframework.data.mongodb.repository.MongoRepository.saveAll(可迭代的实体) 是我用来保存多个文档的文件.
org.springframework.data.mongodb.repository.MongoRepository.saveAll(Iterable entites) is the one which i used to save multiple documents.
这篇关于Java MongoDB一次保存多个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!