Skip to content

Commit 2654fe6

Browse files
benjamnBen Newman
authored andcommitted
Merge pull request #7277 from dburles/mongo-connection-options
User-defined Mongo.setConnectionOptions API for #6958.
1 parent 4d1310b commit 2654fe6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @summary Allows for user specified connection options
3+
* @example http://mongodb.github.io/node-mongodb-native/2.1/reference/connecting/connection-settings/
4+
* @locus Server
5+
* @param {Object} options User specified Mongo connection options
6+
*/
7+
Mongo.setConnectionOptions = function setConnectionOptions (options) {
8+
check(options, Object);
9+
Mongo._connectionOptions = options;
10+
}

packages/mongo/mongo_driver.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ MongoConnection = function (url, options) {
130130
self._observeMultiplexers = {};
131131
self._onFailoverHook = new Hook;
132132

133-
var mongoOptions = {db: {safe: true}, server: {}, replSet: {}};
133+
var mongoOptions = _.extend({db: {safe: true}, server: {}, replSet: {}},
134+
Mongo._connectionOptions);
134135

135136
// Set autoReconnect to true, unless passed on the URL. Why someone
136137
// would want to set autoReconnect to false, I'm not really sure, but
@@ -151,8 +152,8 @@ MongoConnection = function (url, options) {
151152
mongoOptions.db.native_parser = false;
152153
}
153154

154-
// XXX maybe we should have a better way of allowing users to configure the
155-
// underlying Mongo driver
155+
// Internally the oplog connections specify their own poolSize
156+
// which we don't want to overwrite with any user defined value
156157
if (_.has(options, 'poolSize')) {
157158
// If we just set this for "server", replSet will override it. If we just
158159
// set it for replSet, it will be ignored if we're not using a replSet.

packages/mongo/package.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Package.onUse(function (api) {
7474
api.addFiles('local_collection_driver.js', ['client', 'server']);
7575
api.addFiles('remote_collection_driver.js', 'server');
7676
api.addFiles('collection.js', ['client', 'server']);
77+
api.addFiles('connection_options.js', 'server');
7778
});
7879

7980
Package.onTest(function (api) {

0 commit comments

Comments
 (0)