Skip to content
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 error :: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}} #93

Closed
Shaked opened this issue Apr 7, 2016 · 4 comments

Comments

@Shaked
Copy link

Shaked commented Apr 7, 2016

Hey,

We recently switched our production server to PHP7:

$ php -v
PHP 7.0.4-7+deb.sury.org~trusty+2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

And using the new Mongodb driver (1.1.5).

We noticed that sometimes there's a weird behaviour but unfortunately I can't reproduce it yet. When I run the code on dev it works perfectly. I am seeing the following error:

BulkWrite error :: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}
app/vendor/composer/mongodb/mongodb/src/Operation/Update.php (121)
MongoDB\Driver\Server::executeBulkWrite


File:      app/vendor/composer//mongodb-odm-light/lib/Doctrine/MongoDB/Collection.php in line 1397
Method:    MongoCollection->update
Parameter: [['_id' => 'req-a10cd3c3-8485-4d21-9928-239379251472'], ['$set' => ['creatorHostname' => 'prod.cloud.net', 'handledAt' => MongoDate]], ['upsert' => true]]

File:      app/vendor/composer/alcaeus/mongo-php-adapter/lib/Mongo/MongoCollection.php in line 387
Method:    Alcaeus\MongoDbAdapter\ExceptionConverter::toLegacy
Parameter: [MongoDB\Driver\Exception\BulkWriteException]

As you can see, the $set parameter is definitely not empty. I have tried to debug a bit but still can't figure this issue.

I am not sure if this bug should be here or maybe in https://github.com/mongodb/mongo-php-driver/issues

The moment I have a way to reproduce it, will attach a code snippet but maybe in the meanwhile there's something I have missed.

Thank you

@ccovey
Copy link

ccovey commented Apr 7, 2016

I was seeing this last night also but after var_dumping around I was eventually no longer able to reproduce. I chalked it up to an environment issue but maybe that wasn't the case.

Here is a screenshot that shows the filter, update and exception message http://d.pr/i/1ebti. Again I can no longer recreate so not positive that it is in fact the same but interesting that you are getting basically the same error.

EDIT: Also this is using Doctrine ORM and the MongoId is generated with new MongoId($doctrineObject->getId()); Not sure that matters, just more info.

@alcaeus
Copy link
Owner

alcaeus commented Apr 14, 2016

I've taken a look at what you provided and could not find anything that causes this. I've tried using the arguments from the exception message in a test and it doesn't fail:

    $update = ['$set' => ['creatorHostname' => 'prod.cloud.net', 'handledAt' => new \MongoDate()]];
    $this->getCollection()->update(['_id' => 'something'], $update, ['upsert' => true]);
    $this->assertSame(1, $this->getCollection()->count());

I also tried updating a document that already exists, with the same result: works as expected. From what I can see, MongoDB ODM passes an update array that contains changes in the $set operator, so I think we can exclude that as an error source. Type conversion in mongo-php-adapter converts the $set item to a BSONDocument instance (which hopefully shouldn't be a problem) and passes it on to mongo-php-library.

Does the error still come up, and if so, is there anything special about the cases where it comes up? (e.g. always on upsert, only when using BSON types, only when doing multi-updates, and so on).

@Shaked
Copy link
Author

Shaked commented Apr 14, 2016

Hey @alcaeus thanks for the reply. I will investigate more but at the moment I can definitely say that it happens on upsert=true and only when $set is included. I hope I will have more information to share.

Update:

I have also encountered the same problem with $push and $pullAll

@alcaeus
Copy link
Owner

alcaeus commented May 26, 2016

Closing this as it seems this was due to a bug in APCu - and also to consolidate discussion into the driver issue.

@alcaeus alcaeus closed this as completed May 26, 2016
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

No branches or pull requests

3 participants