Setting up MongoDb for Symfony2 using composer
annotations, mongodb, symfony
Solution
I don't know about the PHP version (there might be a problem there, but the error you get doesn't say something about it explicitly), but your problem is the missing configuration in your config.yml.
You must add this even if you don't use the service right now. It does not even have to be valid information, it just must be present.
Add the following to your config.yml (copied from here):
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: test_database
document_managers:
default:
auto_mapping: true
Problem
I'm very new to Symfony2, I have followed the guide on the Symfony2 website to install the MongoDb Doctrine bundles using composer (which is also how I installed Symfony2) http://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/index.html I added the lines into app/autoload.php: ``` use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; AnnotationDriver::registerAnnotationClasses(); ``` and app/AppKernal.php ``` new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(), ``` that were suggested in the guide, but when I try to load the Symfony app (which is just the Demo app) I get the following error: ``` InvalidArgumentException: The service definition "doctrine_mongodb.odm.document_manager" does not exist. ``` [And a lot more trace, let me know if this would be useful] If I comment out the line I added into app/AppKernal.php then the Symfony Demo app loads with no problems. I have run app/check.php and I noticed the following warning: ``` WARNING When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156 Install PHP 5.3.8 or newer if your project uses annotations. ``` I am currently using the PHP version shipped with Ubuntu (5.3.5-1ubuntu7.11) and it looks like the composer/mongodb bits above use Annotations. I can't find anything obvious when I do a Google search and assumed this would be more common if it's really a problem with my PHP version. From what I can tell I will need to either: - Compile PHP from source to upgrade to 5.3.8 - Install Symfony2 not using composer, as it looks like the old way of installing the MongoDB bundles doesn't use annotations - I've totally missed something because I have no idea how Symfony2 works :D Does anyone have any suggestions or other solutions that would be easier? I'd really like to stick with composer if I can.