{"action":"created","issue":{"url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/132","repository_url":"https://api.github.com/repos/alcaeus/mongo-php-adapter","labels_url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/132/comments","events_url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/132/events","html_url":"https://github.com/alcaeus/mongo-php-adapter/issues/132","id":179313217,"number":132,"title":"Call to a member function selectDatabase() on null","user":{"login":"xprt64","id":915088,"avatar_url":"https://avatars.githubusercontent.com/u/915088?v=3","gravatar_id":"","url":"https://api.github.com/users/xprt64","html_url":"https://github.com/xprt64","followers_url":"https://api.github.com/users/xprt64/followers","following_url":"https://api.github.com/users/xprt64/following{/other_user}","gists_url":"https://api.github.com/users/xprt64/gists{/gist_id}","starred_url":"https://api.github.com/users/xprt64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xprt64/subscriptions","organizations_url":"https://api.github.com/users/xprt64/orgs","repos_url":"https://api.github.com/users/xprt64/repos","events_url":"https://api.github.com/users/xprt64/events{/privacy}","received_events_url":"https://api.github.com/users/xprt64/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-26T19:14:55Z","updated_at":"2016-09-27T07:34:58Z","closed_at":null,"body":"I want to use mongo inside a thread and I get an error: `vendor/alcaeus/mongo-php-adapter/lib/Mongo/MongoDB.php:512 Call to a member function selectDatabase() on null`\r\n\r\nBelow is the code that produce this error\r\n```\r\nclass WorkerThread extends \\Thread\r\n{\r\n\r\n\r\n    private $readEvents;\r\n\r\n    private $adapter;\r\n\r\n    public function run()\r\n    {\r\n        try {\r\n            $client = new \\MongoClient();\r\n            $dbName = 'mongo_adapter_test';\r\n\r\n            $client->selectDB($dbName);\r\n\r\n            $this->adapter = new MongoDbEventStoreAdapter(\r\n                new FQCNMessageFactory(),\r\n                new NoOpMessageConverter(),\r\n                $client,\r\n                $dbName\r\n            );\r\n\r\n            $streamName = new StreamName('Prooph\\Model\\User');\r\n            $stream = $this->adapter->load($streamName);\r\n            $readEvents = iterator_to_array($stream->streamEvents());\r\n\r\n            echo sprintf(\"read %d events\", count($readEvents)) . \"\\n\";\r\n            flush();\r\n        } catch (\\Throwable $e) {\r\n            echo 'ERROR! ' . $e->getFile() . ':' . $e->getLine() . ' ' . $e->getMessage() . \"\\n\";\r\n }\r\n    }\r\n\r\n    public function getReadEvents()\r\n    {\r\n        return $this->readEvents;\r\n    }\r\n}\r\n```\r\n\r\nA similar code, but not in a thread, works as expected.\r\n"},"comment":{"url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/comments/249788529","html_url":"https://github.com/alcaeus/mongo-php-adapter/issues/132#issuecomment-249788529","issue_url":"https://api.github.com/repos/alcaeus/mongo-php-adapter/issues/132","id":249788529,"user":{"login":"alcaeus","id":383198,"avatar_url":"https://avatars.githubusercontent.com/u/383198?v=3","gravatar_id":"","url":"https://api.github.com/users/alcaeus","html_url":"https://github.com/alcaeus","followers_url":"https://api.github.com/users/alcaeus/followers","following_url":"https://api.github.com/users/alcaeus/following{/other_user}","gists_url":"https://api.github.com/users/alcaeus/gists{/gist_id}","starred_url":"https://api.github.com/users/alcaeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alcaeus/subscriptions","organizations_url":"https://api.github.com/users/alcaeus/orgs","repos_url":"https://api.github.com/users/alcaeus/repos","events_url":"https://api.github.com/users/alcaeus/events{/privacy}","received_events_url":"https://api.github.com/users/alcaeus/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T07:34:58Z","updated_at":"2016-09-27T07:34:58Z","body":"I'm a bit at a loss here and don't have a lot of experience working with threads in PHP. Could you produce a script for me to run that will reproduce the error? Ideally in form of a unit test, but any script that I can run using `php producing-error.php` works just fine. Thanks!"}}
{"actor":{"display_login":"alcaeus"}}