{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/293","repository_url":"https://api.github.com/repos/mongodb/mongo-php-driver","labels_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/293/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/293/comments","events_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/293/events","html_url":"https://github.com/mongodb/mongo-php-driver/issues/293","id":146978624,"number":293,"title":"BulkWrite error :: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}","user":{"login":"Shaked","id":960015,"avatar_url":"https://avatars.githubusercontent.com/u/960015?v=3","gravatar_id":"","url":"https://api.github.com/users/Shaked","html_url":"https://github.com/Shaked","followers_url":"https://api.github.com/users/Shaked/followers","following_url":"https://api.github.com/users/Shaked/following{/other_user}","gists_url":"https://api.github.com/users/Shaked/gists{/gist_id}","starred_url":"https://api.github.com/users/Shaked/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shaked/subscriptions","organizations_url":"https://api.github.com/users/Shaked/orgs","repos_url":"https://api.github.com/users/Shaked/repos","events_url":"https://api.github.com/users/Shaked/events{/privacy}","received_events_url":"https://api.github.com/users/Shaked/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-04-08T16:40:15Z","updated_at":"2016-04-20T19:22:44Z","closed_at":null,"body":"Hey, \r\n\r\nWe recently switched our production server to PHP7:\r\n```\r\n$ php -v\r\nPHP 7.0.4-7+deb.sury.org~trusty+2 (cli) ( NTS )\r\nCopyright (c) 1997-2016 The PHP Group\r\nZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies\r\n    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies\r\n```\r\n\r\nAnd using the new Mongodb driver (1.1.5). \r\n\r\nWe noticed that sometimes there's a weird behaviour but **unfortunately** I can't reproduce it yet (it's quite random but for sure happens only on PHP7 servers). When I run the code on dev it works perfectly. I am seeing the following error:\r\n\r\n```php\r\nBulkWrite error :: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}\r\napp/vendor/composer/mongodb/mongodb/src/Operation/Update.php (121)\r\nMongoDB\\Driver\\Server::executeBulkWrite\r\n\r\n\r\nFile:      app/vendor/composer//mongodb-odm-light/lib/Doctrine/MongoDB/Collection.php in line 1397\r\nMethod:    MongoCollection->update\r\nParameter: [['_id' => 'req-a10cd3c3-8485-4d21-9928-239379251472'], ['$set' => ['creatorHostname' => 'prod.cloud.net', 'handledAt' => MongoDate]], ['upsert' => true]]\r\n\r\nFile:      app/vendor/composer/alcaeus/mongo-php-adapter/lib/Mongo/MongoCollection.php in line 387\r\nMethod:    Alcaeus\\MongoDbAdapter\\ExceptionConverter::toLegacy\r\nParameter: [MongoDB\\Driver\\Exception\\BulkWriteException]\r\n```\r\n\r\nAs you can see, the `$set` parameter is definitely not empty. I have tried to debug a bit but still can't figure this issue. \r\n\r\nI am not sure if this bug should be here so I opened it also under mongo-php-adapter's repository: https://github.com/alcaeus/mongo-php-adapter/issues/93\r\n\r\nThe moment I have a way to reproduce it, will attach a code snippet but maybe in the meanwhile there's something I have missed. \r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/comments/212567898","html_url":"https://github.com/mongodb/mongo-php-driver/issues/293#issuecomment-212567898","issue_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/293","id":212567898,"user":{"login":"jmikola","id":244663,"avatar_url":"https://avatars.githubusercontent.com/u/244663?v=3","gravatar_id":"","url":"https://api.github.com/users/jmikola","html_url":"https://github.com/jmikola","followers_url":"https://api.github.com/users/jmikola/followers","following_url":"https://api.github.com/users/jmikola/following{/other_user}","gists_url":"https://api.github.com/users/jmikola/gists{/gist_id}","starred_url":"https://api.github.com/users/jmikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmikola/subscriptions","organizations_url":"https://api.github.com/users/jmikola/orgs","repos_url":"https://api.github.com/users/jmikola/repos","events_url":"https://api.github.com/users/jmikola/events{/privacy}","received_events_url":"https://api.github.com/users/jmikola/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T19:22:43Z","updated_at":"2016-04-20T19:22:43Z","body":"The aforementioned ODS tests are being removed in https://github.com/mongodb/mongo-php-driver/pull/303.\r\n\r\n@Shaked: I'm still not having any luck reproducing the issue. I'm attempting to do so with the following script:\r\n\r\n```php\r\n<pre style=\"font-size:1em\"><?php\r\n\r\ndefine('URI', 'mongodb://192.168.112.10:2000');\r\ndefine('NS', 'test.foo');\r\n\r\n$m = new MongoDB\\Driver\\Manager(URI);\r\n\r\n$cmd = new MongoDB\\Driver\\Command(['drop' => explode('.', NS)[1]]);\r\ntry {\r\n    $m->executeCommand(explode('.', NS)[0], $cmd);\r\n} catch (MongoDB\\Driver\\Exception\\RuntimeException $e) {}\r\n\r\n$bulk = new MongoDB\\Driver\\BulkWrite;\r\n$bulk->update(\r\n    ['_id' => 'req-a10cd3c3-8485-4d21-9928-239379251472'],\r\n    ['$set' => ['creatorHostname' => 'prod.cloud.net', 'handledAt' => new MongoDB\\BSON\\UTCDateTime(random_int(0, 999999999))]],\r\n    ['upsert' => true]\r\n);\r\n\r\n$r = $m->executeBulkWrite(NS, $bulk);\r\nprintf(\"nMatched: %d\\n\", $r->getMatchedCount());\r\nprintf(\"nModified: %d\\n\", $r->getModifiedCount());\r\nprintf(\"nUpserted: %d\\n\", $r->getUpsertedCount());\r\n// WriteResult::getUpsertedIds() doesn't handle all ID types (see: PHPC-624)\r\n\r\necho \"\\n\";\r\n\r\n$q = new MongoDB\\Driver\\Query(['_id' => 'req-a10cd3c3-8485-4d21-9928-239379251472']);\r\n$c = $m->executeQuery(NS, $q);\r\n$docs = $c->toArray();\r\nvar_dump($docs);\r\n\r\nif (count((array) $docs[0]) !== 3) {\r\n    fprintf(fopen('php://stderr', 'w'), \"Unexpected upsert:\\n\\n%s\\n\", var_export($docs[0], true));\r\n}\r\n```\r\n\r\nI served this via PHP 7.0.1's built-in web server (e.g. `php -S localhost:8888`) and began spamming hundreds of requests, but the document always has three fields after upserting. I assume it would have only an `_id` field if the problem manifested itself.\r\n\r\nCan you attempt to reproduce using this script, or otherwise tweak it?"}}