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
BulkWrite operations fails on references with extra fields #159
Comments
Per the DBRef documentation:
Also, there is this definition from SERVER-12263:
That said, I'm not sure why the server seems to allow this:
The exception is most certainly due to the C driver's Is ODM creating these out-of-order values? |
We create references with https://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L667 We create them in order as far as I can tell. |
It appears that it is actually our test that is broken. We have a test where the reference is manually created and it is created out of order. |
From what I can tell, ODM creates them in the correct order, also mongo-php-adapter just loops over the document for conversion purposes, so no re-ordering should occur there.
Reading the DBRef documentation, this is indeed the case but seems to not be applied to documents being inserted or updated with update operators. If the exception occurs on replace, it most definitely should also occur on inserts and updates as well. |
Based on @jwage's response above, this was caused by a test creating an invalid DBRef document. It's unfortunate that the server doesn't consider such documents invalid for insert/update, but I don't fault the driver here. This was only picked up because we need to check that BSON documents do not contain |
Great, thanks @jmikola! |
This was previously reported in alcaeus/mongo-php-adapter#101. Doing a BulkWrite update with certain documents causes the following warning:
mongoc: WARNING > mongoc_bulk_operation_replace_one(): replacement document may not contain $ or . in keys. Ignoring document.
.Looking into the error I've found that this occurs when doing a bulk write containing a reference that has an extra field before
$ref
:This error does not occur when passing the extra field in the DBRef document at the end, e.g.
['$ref' => 'collection', '$id' => 2, 'type' => 'test']
.On the other hand, doing the very same thing in an update operation does not cause this error, the update goes through just fine. I'll be adding a pull request containing three tests for the scenarios: replace with an extra field after the reference, replace with an extra field before the reference and an update with an extra field before the reference.
The text was updated successfully, but these errors were encountered: