Reputation: 196
I have two MongoDB instances - one slave and one master. There is an Arbiter too.
Basically the setup is the following:
(Image Source: https://docs.mongodb.com/manual/replication/)
In my Symfony application, in config.yml I have this for MongoDB:
# Mongo DB
doctrine_mongodb:
connections:
default:
server: %database_mongodb_access%
options: {}
default_database: %database_mongodb_name%
document_managers:
default:
auto_mapping: true
where %database_mongodb_access%
is 'mongodb://mongo:27017'
.
How to configure my Symfony/Doctrine application to automatically failover to the slave MongoDB instance if the primary fails, so the application continues working?
It is not clear to me from the docs: http://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html
Upvotes: 1
Views: 2249
Reputation: 20185
It is possible to connect to several mongodb servers on one connection if you are using a replica set by listing all of the servers within the connection string as a comma separated list.
doctrine_mongodb:
# ...
connections:
default:
server: "mongodb://mongodb-01:27017,mongodb-02:27017,mongodb-03:27017"
And check the retry mechanism for failover :
Upvotes: 1