Skip to content

Improve SimpleMongoRepository.saveAll to use batch updates - #5221

Open
syjdev wants to merge 6 commits into
spring-projects:mainfrom
syjdev:issue/5220
Open

Improve SimpleMongoRepository.saveAll to use batch updates#5221
syjdev wants to merge 6 commits into
spring-projects:mainfrom
syjdev:issue/5220

Conversation

@syjdev

@syjdev syjdev commented Jul 1, 2026

Copy link
Copy Markdown
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Closes #5220

syjdev added 2 commits July 2, 2026 00:50
Signed-off-by: syjdev <syjdev@gmail.com>
Signed-off-by: syjdev <syjdev@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 1, 2026
syjdev added 3 commits July 2, 2026 01:11
Signed-off-by: syjdev <syjdev@gmail.com>
…ties.

Signed-off-by: syjdev <syjdev@gmail.com>
@mp911de

mp911de commented Jul 27, 2026

Copy link
Copy Markdown
Member

As per #5220 (comment), we should seek a consistent bulk approach for inserts and updates, also considering the reactive implementation.

@syjdev

syjdev commented Jul 29, 2026

Copy link
Copy Markdown
Author

Thank you for the feedback. I'll revise the implementation based on both your comment on #5220 and the feedback you've provided here. Thanks!

Move the imperative and reactive saveAll(Iterable) onto bulkWrite(...) so that
inserts and replaces run within a single ordered bulk. BulkWriter now propagates
identifiers generated during the write back to the entity, which saveAll(...)
needs to return saved entities. Versioned entities remain saved one by one.

Signed-off-by: syjdev <syjdev@gmail.com>
@syjdev

syjdev commented Jul 31, 2026

Copy link
Copy Markdown
Author

I moved both the imperative and the reactive saveAll(Iterable) onto
bulkWrite(Bulk, BulkWriteOptions).

Also, I changed BulkWriter/ReactiveBulkWriter to propagate the generated _id
back to the entity after the write because, unlike doInsert(…), the bulk insert
path did not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve MongoRepository.saveAll to use batch updates

3 participants