私はSymfony2をMongoDBに次のように接続しようとしています:
- DoctrineMongoDBBundleを
AppKernel::registerBundles
メソッドに登録します - '
doctrine_mongo_db
'構成を設定します(以下を参照config.yml
) - 動作
doctrine.odm.mongodb.document_manager
中のコンテナから ''を取得HelloController
そして、アプリケーションを実行しようとすると、MongoConnectionExceptionがスローされます。
誰かが私がこの問題を解決するのを手伝ってくれる?
AppKernel.php
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\DoctrineMongoDBBundle\DoctrineMongoDBBundle(),
new Sensio\HelloBundle\HelloBundle()
);
return $bundles;
}
config.yml
framework:
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
templating: { engines: ['twig'] }
## Doctrine Configuration
doctrine_mongo_db:
server: mongodb://root:root@192.168.0.111:27017
default_database: test
options: { connect: true }
mappings:
HelloBundle: { type: annotation, dir: Document }
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
HelloController.php
/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
$dm = $this->get('doctrine.odm.mongodb.document_manager');
例外(96行目)
connecting to failed: Transport endpoint is not connected
in ~/vendor/doctrine-mongodb/lib/Doctrine/MongoDB/Connection.php line 96 »
93. if ($this->server) {
94. $this->mongo = new \Mongo($this->server, $this->options);
95. } else {
96. $this->mongo = new \Mongo();
97. }