This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Symfony2 MongoDB Multiple connections error

Installation and environment issues, mainly on 1.x but there's some 2.x here too.

Symfony2 MongoDB Multiple connections error

by nicom974 » Wed Mar 04, 2015 2:15 am

I have an issue setting up MongoDB in Symfony2.

Specs:

Code: Select all
"Symfony": "2.6.*"
"doctrine/mongodb-odm": "1.0.*@dev",
"doctrine/mongodb-odm-bundle": "3.0.*@dev"


I have 2 databases used in 2 different bundles, nxtlog and nxtsurvey, in MongoDB. The original issue I had was that the db name I added in options was not taken into account, which resulted in database 'default' to be used, which of course does not exist. I also do not want to add default_connection and default_manager, nor even default_database as both connections are used in not-core bundles.

==== Attempt #1 ====

Here is the original config I had:

Code: Select all
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: ~

In order to make it work, I added the name of the db in each Document annotations:

Code: Select all
/**
 * @MongoDB\Document(db="nxtlog")
 */
class ErrorLogs


Which is a temporary solution, but since my plan is to reuse the bundles in my other projects, I do not want to have to go through all documents and set the name of the db.

==== Attempt #2 ====

My second attempt was to rigorously follow the documentation, and therefore I tried the following:

Code: Select all
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:

Code: Select all
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 figured out that I could not have different names for connections and data-managers. Which I did not believe, so I googled it, and someone had a similar issue, and the answer was to add the following under doctrine_mongodb:
Code: Select all
default_commit_options: ~


But this solution did not work for me, and after more googling, I found out that jmikola, the guy who wrote the bundle (or parts of it), made a mistake, he said he fixed it, and that default_commit_options should not be a required configuration option. (ref. https://github.com/doctrine/DoctrineMon ... issues/222)

At this point I would need some help, because this is taking far too much time to solve.

Thanks
nicom974
Junior Member
 
Posts: 4
Joined: Tue Dec 03, 2013 7:07 am