I have a problem setting up MongoDB in Symfony2.
Specifications:
"Symfony": "2.6.*" "doctrine/mongodb-odm": "1.0.*@dev", "doctrine/mongodb-odm-bundle": "3.0.*@dev"
I have 2 databases used in two different packages, nxtlog and nxtsurvey, in MongoDB. The original problem was that the db name that I added in the parameters was not taken into account, which led to the use of the default database, which, of course, does not exist. I also do not want to add default_connection and default_manager, and even default_database, since both connections are used in non-core packages.
==== Attempt # 1 ====
Here is the original configuration I had:
doctrine_mongodb: connections: nxtlog: server: "%nxtlog_database_server%" options: username: "%nxtlog_database_username%" password: "%nxtlog_database_password%" db: "%nxtlog_database_name%" nxtsurvey: server: "%nxtsurvey_database_server%" options: username: "%nxtsurvey_database_username%" password: "%nxtsurvey_database_password%" db: "%nxtsurvey_database_name%" document_managers: nxtlog: mappings: NxtLogBundle: ~ nxtsurvey: mappings: NxtVibeSurveyBundle: ~
To make it work, I added the db name to each document annotation:
class ErrorLogs
This is a temporary solution, but since my plan is to reuse packages in my other projects, I do not want to go through all the documents and set the db name.
==== Attempt # 2 ====
My second attempt was to strictly follow the documentation, and so I tried the following:
doctrine_mongodb: connections: nxtlog_conn: server: "%nxtlog_database_server%" options: username: "%nxtlog_database_username%" password: "%nxtlog_database_password%" connect: true db: "%nxtlog_database_name%" nxtsurvey_conn: server: "%nxtsurvey_database_server%" options: username: "%nxtsurvey_database_username%" password: "%nxtsurvey_database_password%" connect: true db: "%nxtsurvey_database_name%" document_managers: nxtlog_dm: connection: nxtlog_conn mappings: NxtLogBundle: ~ nxtsurvey_dm: connection: nxtsurvey_conn mappings: NxtVibeSurveyBundle: ~
And get the following error:
ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58: The service "doctrine_mongodb.odm.nxtlog_conn_connection" has a dependency on a non-existent service "doctrine_mongodb.odm.nxtlog_conn_configuration".
So, I realized that I cannot have different names for connections and data managers. Which I did not believe, so I was looking for it, and someone had a similar problem, and the answer was to add the following to doctrine_mongodb:
default_commit_options: ~
But this solution did not work for me, and after more searches, I found out that jmikola, the guy who wrote the kit (or parts of it) made a mistake, he said that he fixed it, and that default_commit_options should not be a required configuration . (link https://github.com/doctrine/DoctrineMongoDBBundle/issues/222 )
At this point, I will need help because it takes too much time.
thanks