Problem while connecting mogos (Query router) though morphium
Closed this issue · 2 comments
Hi,
I am trying to connect mongos through morphium.
Code sample:
private static Morphium getMorphium() throws UnknownHostException {
Morphium morphium = null;
MorphiumConfig cfg = new MorphiumConfig();
cfg.addHostToSeed("xx.xx.x.xxx:27017");
cfg.setDatabase("testdb");
MorphiumSingleton.setConfig(cfg); // Create a singleton object
morphium = MorphiumSingleton.get();
System.out.println("Connected with database....");
return morphium;
}
Error :
Caused by: com.mongodb.MongoCommandException: Command failed with error 20: '' on server xx.xx.x.xxx:27015. The full response is { "$err" : "can't use 'local' database through mongos", "code" : 20 }
Solution i tried :
I commented below lines in de.caluga.morphium.driver.mongodb.Driver class (Line no : 315) and created jar and used it. That is working fine.
Document res = mongo.getDatabase("local").runCommand(new BasicDBObject("isMaster", true));
if (res.get("setName") != null) {
replicaset = true;
}
Is this the write way to solve the problem or is the any other solution for this ?
Hi,
if you comment out this line of code, morphium won’t work with „normal“ replicasets anymore. Seems like, we need to add suppport for mongos at some point. Thanks for bringing that to my attention…
Cheers,
Stephan
Am 10.02.2016 um 16:42 schrieb kiran Naikwade <notifications@github.com mailto:notifications@github.com>:
Hi,
I am trying to connect mongos through morphium.Code sample:
private static Morphium getMorphium() throws UnknownHostException {
Morphium morphium = null;
MorphiumConfig cfg = new MorphiumConfig();
cfg.addHostToSeed("xx.xx.x.xxx:27017");
cfg.setDatabase("testdb");
cfg.setMongoLogin("testuser");
cfg.setMongoPassword("testpass");
MorphiumSingleton.setConfig(cfg); // Create a singleton object
morphium = MorphiumSingleton.get();
System.out.println("Connected with database....");
return morphium;
}
Error :
Caused by: com.mongodb.MongoCommandException: Command failed with error 20: '' on server xx.xx.x.xxx:27015. The full response is { "$err" : "can't use 'local' database through mongos", "code" : 20 }Solution i tried :
I commented below lines in de.caluga.morphium.driver.mongodb.Driver class (Line no : 315) and created jar and used it. That is working fine.Document res = mongo.getDatabase("local").runCommand(new BasicDBObject("isMaster", true)); if (res.get("setName") != null) { replicaset = true; }
Is this the write way to solve the problem or is the any other solution for this ?
—
Reply to this email directly or view it on GitHub #19.
Hi,
I created a fix in the development branch - should actually work for your case. Mind to test it?
Cheers,
Stephan
Am 10.02.2016 um 16:49 schrieb Stephan Bösebeck stephan@boesebeck.biz:
Hi,
if you comment out this line of code, morphium won’t work with „normal“ replicasets anymore. Seems like, we need to add suppport for mongos at some point. Thanks for bringing that to my attention…
Cheers,
Stephan
Am 10.02.2016 um 16:42 schrieb kiran Naikwade <notifications@github.com mailto:notifications@github.com>:
Hi,
I am trying to connect mongos through morphium.Code sample:
private static Morphium getMorphium() throws UnknownHostException {
Morphium morphium = null;
MorphiumConfig cfg = new MorphiumConfig();
cfg.addHostToSeed("xx.xx.x.xxx:27017");
cfg.setDatabase("testdb");
cfg.setMongoLogin("testuser");
cfg.setMongoPassword("testpass");
MorphiumSingleton.setConfig(cfg); // Create a singleton object
morphium = MorphiumSingleton.get();
System.out.println("Connected with database....");
return morphium;
}
Error :
Caused by: com.mongodb.MongoCommandException: Command failed with error 20: '' on server xx.xx.x.xxx:27015. The full response is { "$err" : "can't use 'local' database through mongos", "code" : 20 }Solution i tried :
I commented below lines in de.caluga.morphium.driver.mongodb.Driver class (Line no : 315) and created jar and used it. That is working fine.Document res = mongo.getDatabase("local").runCommand(new BasicDBObject("isMaster", true)); if (res.get("setName") != null) { replicaset = true; }
Is this the write way to solve the problem or is the any other solution for this ?
—
Reply to this email directly or view it on GitHub #19.