In Spring MongoDB is it possible to upsert a collection in bulk, i.e without iterating it and saving every item separately?
Printable View
In Spring MongoDB is it possible to upsert a collection in bulk, i.e without iterating it and saving every item separately?
The short answer is no. But not because of Spring Data, but because bulk upserts in Mongo are not supported. I believe it is a JIRA/Feature that might show up later in future versions of Mongo.
I have had this issue before myself with Mongo, no Spring Data usage. And I always had to really think about what I wanted done and come up with either a different document model, or another alternative.
For instance, in one case, instead of upserting different elements in a collection, I would update the entire collection. So I would get the document, get the collection and modify it in code, then do a $set on the collection to the new version of it. It will still be an update statement which allows for WriteConcerns rather than a full document replacement in the database.
Hope that helps, and sorry almost a month since you first posted this, so you probably already came up with an alternative.
Mark