Skip to content
Snippets Groups Projects
Commit 81674b76 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

Feature: allow configs to turn off mongoose autoIndex feature

parent fbcadd1e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -5,18 +5,6 @@ var mongodbArbiterDiscover = require('mongodb-arbiter-discovery');
var mongoDogStats = require('mongodb-datadog-stats');
var shutdown = require('shutdown');
 
var MONGO_CONNECTION_OPTIONS = {
server: {
keepAlive: 1,
auto_reconnect: true,
socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 }
},
replset: {
keepAlive: 1,
auto_reconnect: true,
socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 }
}
};
 
module.exports = function mongooseConnectionConfigurer(options) {
var mongoose = options.mongoose;
Loading
Loading
@@ -35,10 +23,34 @@ module.exports = function mongooseConnectionConfigurer(options) {
var mongoConnection = config.get("mongo:connection");
var mongooseConnectionUrl = config.get("mongo:url");
 
var autoIndex;
if (config.get('mongo:noAutoIndex')) {
autoIndex = false;
} else {
autoIndex = true;
}
var mongooseConnectOptions = {
server: {
keepAlive: 1,
auto_reconnect: true,
socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 }
},
replset: {
keepAlive: 1,
auto_reconnect: true,
socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 }
},
config: {
autoIndex: autoIndex
}
};
if (mongoConnection) {
mongooseConnectionUrl = mongodbConnString.mongo(mongoConnection);
}
mongoose.connect(mongooseConnectionUrl, MONGO_CONNECTION_OPTIONS);
mongoose.connect(mongooseConnectionUrl, mongooseConnectOptions);
 
shutdown.addHandler('mongo', 1, function(callback) {
mongoose.disconnect(callback);
Loading
Loading
@@ -90,7 +102,7 @@ module.exports = function mongooseConnectionConfigurer(options) {
if(err) return die(err);
 
mongoConnection.hosts = hosts;
mongoose.connect(mongodbConnString.mongo(mongoConnection), MONGO_CONNECTION_OPTIONS);
mongoose.connect(mongodbConnString.mongo(mongoConnection), mongooseConnectOptions);
});
}
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment