0

How to configured mongo cluster details (it uses two servers) in Spring MVC applicationContext.xml?

<mongo id="mongo" host="${mongo.db.host}" port="${mongo.db.port}"/>

database.properties

mongo.db.host=server1
mongo.db.port=27017

My mongodb is clustered database shared load balancing between two server (server1 and server2)? What configuration I need to use so that my application points to both databases? Please help provide pointers/answers?

1 Answer 1

1

If by cluster you mean a shard environment, then you connect to mongos. In that case you give the host and port of the mongos instance you are connecting to, but the XML configuration should be the same.

If however you mean a replica set, your configuration should look like:

<mongo id="mongo" replica-set="${mongo.db.replica-set}" />

database.properties

mongo.db.replica-set=server1:27017,server2:27017

Replace server1 and server2 with real server names. The principal is a list of host:port entries separated by commas.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.