Skip to content

Commit 9380a91

Browse files
committed
If only a single mongos is provided in the seedlist, fix issue where it would be assigned as single standalone server instead of mongos topology (Issue #130).
1 parent 46404e2 commit 9380a91

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.2.7
2+
----------------
3+
* If only a single mongos is provided in the seedlist, fix issue where it would be assigned as single standalone server instead of mongos topology (Issue #130).
4+
15
2.2.6 2016-08-16
26
----------------
37
* Updated mongodb-core to 2.0.8.

lib/mongo_client.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,22 @@ function createServer(options, callback) {
196196
// Set default options
197197
var servers = translateOptions(options);
198198
// Create Db instance
199-
new Db(options.dbName, servers[0], options).open(callback);
199+
new Db(options.dbName, servers[0], options).open(function(err, db) {
200+
if(err) return callback(err);
201+
// Check if we are really speaking to a mongos
202+
var ismaster = db.serverConfig.lastIsMaster();
203+
204+
// Do we actually have a mongos
205+
if(ismaster && ismaster.msg == 'isdbgrid') {
206+
// Destroy the current connection
207+
db.close();
208+
// Create mongos connection instead
209+
return createMongos(options, callback);
210+
}
211+
212+
// Otherwise callback
213+
callback(err, db);
214+
});
200215
}
201216

202217
function connectHandler(options, callback) {

0 commit comments

Comments
 (0)