@monti-apm/mongo-sharded-cluster
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -15,3 +15,3 @@ var async = require('async'); | ||
MongoShardedCluster.prototype.addShard = function(name, conn) { | ||
MongoShardedCluster.prototype.addShard = function(name, conn, client) { | ||
var self = this; | ||
@@ -25,3 +25,4 @@ if(self._shardMap[name]) { | ||
size: null, | ||
name: name | ||
name: name, | ||
client: client | ||
}; | ||
@@ -106,3 +107,7 @@ }; | ||
MongoShardedCluster.initFromEnv = function(callback) { | ||
MongoShardedCluster.initFromEnv = function(connectOptions, callback) { | ||
if (typeof connectOptions === 'function') { | ||
callback = connectOptions; | ||
connectOptions = {}; | ||
} | ||
var mongoCluster = new MongoShardedCluster(); | ||
@@ -117,8 +122,8 @@ var envKeys = _.keys(process.env); | ||
var mongoUrl = process.env[key]; | ||
MongoClient.connect(mongoUrl, { | ||
MongoClient.connect(mongoUrl, Object.assign({ | ||
useUnifiedTopology: true | ||
}, function(err, conn) { | ||
if(conn) { | ||
const db = conn.db(); | ||
mongoCluster.addShard(shardName, db); | ||
}, connectOptions), function(err, client) { | ||
if(client) { | ||
const db = client.db(); | ||
mongoCluster.addShard(shardName, db, client); | ||
} | ||
@@ -125,0 +130,0 @@ done(err); |
{ | ||
"name": "@monti-apm/mongo-sharded-cluster", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Shard MongoDB in the app layer and build a MongoDB cluster", | ||
@@ -26,4 +26,4 @@ "main": "lib/index.js", | ||
"async": "1.4.x", | ||
"mongodb": "^3.6.7", | ||
"underscore": "^1.13.1" | ||
"mongodb": "^3.7.3", | ||
"underscore": "^1.13.4" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -139,3 +139,22 @@ var MongoShardedCluster = require('../lib/index.js'); | ||
}); | ||
it("should support options", function(done) { | ||
process.env["MONGO_SHARD_URL_one"] = "mongodb://localhost/easy-shard"; | ||
process.env["MONGO_SHARD_URL_two"] = "mongodb://localhost/easy-shard"; | ||
MongoShardedCluster.initFromEnv( { | ||
useUnifiedTopology: false | ||
}, function(err, cluster) { | ||
assert.ifError(err); | ||
assert.ok(cluster.getConnection("one")); | ||
assert.ok(cluster.getConnection("two")); | ||
const conn = cluster.getConnection("one"); | ||
assert.ok(typeof conn.collection === 'function'); | ||
delete process.env["MONGO_SHARD_URL_one"]; | ||
delete process.env["MONGO_SHARD_URL_two"]; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
10927
258
10
Updatedmongodb@^3.7.3
Updatedunderscore@^1.13.4