Java MongoDB save multiple documents at once

Arun Kumar V picture Arun Kumar V · Jun 6, 2018 · Viewed 12k times · Source

I Have a list of updated objects/documents i need save all the objects in the list at once.

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 ?

Answer

Arun Kumar V picture Arun Kumar V · Jun 6, 2018

Thanks for all the help.

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(Iterable entites) is the one which i used to save multiple documents.