Skip to content

Support for BulkWrite into multiple collections.#5169

Closed
christophstrobl wants to merge 8 commits intomainfrom
issue/5087
Closed

Support for BulkWrite into multiple collections.#5169
christophstrobl wants to merge 8 commits intomainfrom
issue/5087

Conversation

@christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Feb 24, 2026

This PR introduces a new Bulk API that allows to prepare a bulk independently from MongoOperations.
The decoupling of the actual bulk to execute and the underlying operations allows for better read and maintainability.

Since multi collection bulk writes require MongoDB 8.0+ the execution layer makes sure to still route single collection bulk writes to the collection API so that users with older MongoDB Server generations are able use the new API without having to upgrade their server.

Bulk bulk = Bulk.create(builder -> builder
        .inCollection(Person.class, spec -> spec
                .insert(person1)
                .insert(person2)
                .upsert(where("_id").is("..."), new Update().set("firstname", "...")))
        .inCollection(User.class, spec -> spec.insert(new User("..."))));

BulkWriteResult result = template.bulkWrite(bulk, BulkWriteOptions.ordered());

Closes: #5087

@mp911de mp911de added the type: enhancement A general enhancement label Feb 26, 2026
@mp911de mp911de added this to the 5.1 M2 (2026.0.0) milestone Feb 26, 2026
Introduce CollectionName abstraction. Reduce duplications between BulkWriter and ReactiveBulkWriter. Use PersistentEntity instead of a Class and Entity mix.

Remove inCollection(…).update style in favor of capturing inCollection(…, it -> update) style to avoid two programming models. Remove typing to allow usage of Document and entities with the bulk API.
christophstrobl added a commit that referenced this pull request Mar 3, 2026
For bulk write operations we decoupled the Bulk from the actual execution.
This eliminates the need to go through a dedicated BulkOperations interface and enables direct use via MongoOperations.
In difference to the existing BulkOperations, Lifecycle events and conversions are triggered on calling the bulk write method on MongoOperations.
In case of ongoing transaction the active ClientSession is passed on to method calls on MongoClient.

See: #5087
Original Pull Request: #5169
christophstrobl pushed a commit that referenced this pull request Mar 3, 2026
Also, use PersistentEntity instead of a Class and Entity mix.

Remove inCollection(…).update style in favor of capturing inCollection(…, it -> update) style to avoid two programming models. Remove typing to allow usage of Document and entities with the bulk API.

See: #5087
Original Pull Request: #5169
@christophstrobl christophstrobl deleted the issue/5087 branch March 3, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Bulk Write into multiple collections.

2 participants