I have a script running which finds data in a database I have. For some reason after a short period of time, it stops finding any data but does not output any errors to the screen or through node.js. Here is the following setup I have for mongoose. I have a database at MLAB btw!
var connectionOptions = {
server: {
auto_reconnect: true,
poolSize: 16,
socketOptions: {
keepAlive: 120,
connectTimeoutMS: 5 * 60 * 60 * 1000,
socketTimeoutMS: 5 * 60 * 1000
}
},
replset: {
poolSize: 16,
socketOptions: {
connectTimeoutMS: 300000, // 5 minutes
keepAlive: 120
},
ha: true, // Make sure the high availability checks are on
haInterval: 5000, // Run every 10 seconds
}
};
//mongoose.set('debug', true);
mongoose.connect('mongodb://[email protected]:57328,XXXXXXXX.mlab.com:57328/XXXXXXXXX?replicaSet=rs-XXXXXX', connectionOptions, function (err) {
if (err) console.log(err);
});
mongoose.connection.on('connecting', function () {
console.log('Connecting to MongoDB...');
});
mongoose.connection.on('connected', function () {
console.log('MongoDB connected!');
});
mongoose.connection.on('open', function () {
console.log('MongoDB connection opened!');
});
mongoose.connection.on('error', function (err) {
console.log(err);
mongoose.disconnect();
});
mongoose.connection.on('disconnected', function () {
console.log('MongoDB disconnected!');
mongoose.connect('mongodb://[email protected]:57328,XXXXXXXX.mlab.com:57328/XXXXXXXXX?replicaSet=rs-XXXXXX', connectionOptions, function (err) {
if (err) console.log(err);
});
});
mongoose.connection.on('reconnected', function () {
console.log('MongoDB reconnected!');
});
mongoose.connection.on('close', function () {
console.log.error('MongoDB closed');
});
mongoose.connection.on('ha', function(type, data) {
console.log('replset ha ' + type);
});
mongoose.connection.on('timeout', function () {
console.log.error('MongoDB timeout');
});
I have seen a lot of configurations and I've tried a ton of different things but nothing seems to work.
I would really appreciate the help, as I've been researching around for quite a bit to no luck.
And to recap again, I have a script running querying records from a database, and after a certain time, the script will keep running but seem to not find any new records and stop responding to any new data.
mongod
logs, or is there any error printed by the application? I assume the endpoint keeps a database connection open for ~5 hours and it's possible that it's timing out on something – Immediacy