3

In a reactive spring boot application, I have a list of items to update. I want to send a SINGLE command to my DB to apply the changes on different items. An equivalent to db.collection.updateMany if I may say. Is it possible? How?

Iori Yagami
  • 387
  • 1
  • 3
  • 18

1 Answers1

0

Yes it is possible, ReactiveMongoTemplate has

updateMulti(Query query, UpdateDefinition update, Class<?> entityClass)

Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.

Lucia
  • 791
  • 1
  • 8
  • 17
  • If I use the query to find the item 1 in the items list, I can update it with the UpdateDefinition I guess. What about the item 2? item 3 ... ? Do I need to write as many updateMulti as items to update? If so, I can just use the repository saveAll. What I need, is to send a SINGLE mongodb command to update all the items. – Iori Yagami Aug 24 '21 at 11:52
  • YEah you can use saveAll() or insert(Collection extends T> batchToSave, Class> entityClass) Insert a Collection of objects into a collection in a single batch write to the database. reactor.core.publisher.Flux insert(Collection extends T> batchToSave, String collectionName) Insert a batch of objects into the specified collection in a single batch write to the database. – Lucia Aug 24 '21 at 12:32
  • insert doesn't update. saveAll does update but not in a SINGLE batch. What I need is a way to update in a single batch. – Iori Yagami Aug 24 '21 at 14:14
  • @lori Yagami, did you get a solution for this ? – ravikant Oct 22 '21 at 18:54