Skip to content

Feature: Client Bulk Write #1818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v2.x
Choose a base branch
from
Open

Feature: Client Bulk Write #1818

wants to merge 3 commits into from

Conversation

jmikola and others added 2 commits April 16, 2025 09:13
* PHPC-2495, PHPC-2490, PHPC-2491, PHPC-2492: BulkWriteCommand ctor and ops

* PHPC-2494: BulkWriteCommandResult and BulkWriteCommandException

It was possible to reuse WriteConcernError and WriteError with slight changes to their init functions.

* Include missing header in WriteResult.h

This was not necessary for compilation, but it makes the header internally consistent.

* PHPC-2493: Manager and Server::executeBulkWriteCommand()

* PHPC-2494: Handle null error fields in BulkWriteCommandResult

Always return arrays for writeErrors and writeConcernErrors

* PHPC-2494: Return writeErrors as an associative array

* PHPC-2493: Revise error handling for mongoc_bulkwrite_execute

* Consistent WriteError and WriteConcernError parsing for bulk write results

* BulkWriteCommand tests

* clang-format

* Remove BulkWriteCommandResult::getServer()

Per CDRIVER-5843, libmongoc does not consistently populate this field. It also isn't required by the spec, so omit it for now.

* Check for _id extraction before appending insert

* Regenerate BulkWriteCommandException arginfo

* PHPC-2493: Relocate writeConcern option to executeBulkWriteCommand()

* Parse sort option for replaceOne and updateOne

* BulkWriteCommand::replaceOne() need not accept root-level arrays

* Preserve empty documents for verbose results and error reply

Result maps should only be null if verboseResults=false. Additionally, the error reply document can default to an empty document on error (as it is in libmongoc).

* PHPC-2494: Relocate error fields to BulkWriteCommandException

Revise the stubs to reflect that executeBulkWriteCommand() always returns a BulkWriteCommandResult. If the result is unacknowledged, that is reported via isAcknowledged() and other methods can throw, which is consistent with WriteResult for the legacy bulk write API.

If the result is empty on error (i.e. no writes were successful), BulkWriteCommandException::$partialResult is left unset.

* Throw BulkWriteCommandException directly for server errors

This also ensures that BulkWriteCommandException uses the original server-side error code and message (if available) for top-level errors.

* Check for empty error_reply instead of NULL

mongoc_bulkwriteexception_errorreply() always returns an initialized document, but it may be empty. This ensures that an InvalidArgumentException is not unnecessarily proxied behind a BulkWriteCommandException.
@alcaeus alcaeus marked this pull request as ready for review May 7, 2025 11:18
@alcaeus alcaeus requested a review from a team as a code owner May 7, 2025 11:18
@alcaeus alcaeus requested review from alcaeus and removed request for a team May 7, 2025 11:18
Comment on lines +22 to +38
object(MongoDB\Driver\BulkWriteCommand)#%d (%d) {
["bypassDocumentValidation"]=>
bool(true)
["comment"]=>
string(3) "foo"
["let"]=>
object(stdClass)#%d (%d) {
["foo"]=>
int(1)
}
["ordered"]=>
bool(true)
["verboseResults"]=>
bool(true)
["session"]=>
NULL
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BulkWriteCommand class doesn't expose the list of operations in var_dump or xdebug. The only way to see its state is by executing it and using a subscriber to get the raw command.
Can we add a (virtual) property to show them or is there a limitation in libmongoc?

Comment on lines +22 to +38
object(MongoDB\Driver\BulkWriteCommand)#%d (%d) {
["bypassDocumentValidation"]=>
bool(true)
["comment"]=>
string(3) "foo"
["let"]=>
object(stdClass)#%d (%d) {
["foo"]=>
int(1)
}
["ordered"]=>
bool(true)
["verboseResults"]=>
bool(true)
["session"]=>
NULL
}
Copy link
Member Author

@GromNaN GromNaN May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BulkWriteCommand doesn't expose the list of operations when using var_dump or xdebug. There is no way to inspect its contents without executing it and using a subscriber to get the raw command.

I think the executed property should also be exposed, as it cannot be executed multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants