I have a web application running on Node, express and MongoDB. I use mongoose as the ODM. When i tested my application with mongodb version v3.0.1 it runs fine and throws no errors. But when i run the same code v3.2.10 i get a connection timeout after some time.
I get the following Error :
Error: connection timeout at null.<anonymous> (/webapp/node_module/mongoose/lib/drivers/node-mongodb-native/connection.js:186:17)
I use mongoose.connect for the db connection to the local mongodb instance. Has anything changed in the way of connection ?
The buffering timeout is usually due to either registering models on a newly created connection but using mongoose. connect() : const mongoose = require('mongoose'); const schema = new mongoose.
You should close a mongoose connection when a Node POSIX signal is happening. SIGINT process is triggered when Ctrl-C has been pressed on terminal or a server shutdown. Another possible scenario is to close a connection when a data streaming is done.
Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.
serverSelectionTimeoutMS - With useUnifiedTopology , the MongoDB driver will try to find a server to send any given operation to, and keep retrying for serverSelectionTimeoutMS milliseconds. If not set, the MongoDB driver defaults to using 30000 (30 seconds).
I had this problem a while ago. It all depends on which version of mongoose
and mongodb-core
you are using. Right now, you have to specify the following parameters:
mongoose.connect("mongodb://user:password@address/db", {
server: {
socketOptions: {
socketTimeoutMS: 0,
connectionTimeout: 0
}
}
});
However, just yesterday, the correct parameters where
mongoose.connect("mongodb://user:password@address/db", {
server: {
socketOptions: {
socketTimeoutMS: 0,
connectTimeoutMS: 0
}
}
});
I don't really know what to believe in anymore..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With