I am using Morphia.
And now I have two mongoDB server:
'mongodb://user:[email protected]:3800,server2.com:3717/testDb?replicaSet=mgset-502725001'
How can I connect both server by Morphia?
I can only connet one server right now:
@Bean(name = "mongoClient")
public MongoClient mongoClient() {
List<MongoCredential> credentialsList = new ArrayList<MongoCredential>();
MongoCredential credentia = MongoCredential.createCredential(
mongoDbUserName, mongoDbDatabase, mongoDbPassword.toCharArray());
credentialsList.add(credentia);
MongoClientOptions clientOptions = MongoClientOptions.builder()
.maxConnectionIdleTime(6000 * 5)
.maxConnectionLifeTime(0)
.build();
// only one server here
ServerAddress addr = new ServerAddress("server1.com", 3800);
return new MongoClient(addr, credentialsList, clientOptions);
}
question from:
https://stackoverflow.com/questions/65933204/how-can-i-handle-multiple-server-mongodb-with-morphia 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…