Since today morning, my application stopped connecting to mongodb. its getting timeout.
48ed670c0dddfa:/app# node <<‘EOF’
> const mongoose = require(‘mongoose’);
>
> const uri = process.env.MONGODB_URI;
>
> console.log(‘[Test] MONGODB_URI is’, uri ? ‘SET’ : ‘NOT SET’);
> if (!uri) {
> console.error(‘[Test] No MONGODB_URI found in env’);
> process.exit(1);
> }
>
> mongoose.set(‘bufferCommands’, false);
>
> mongoose.connect(uri, {
> maxPoolSize: 10,
> socketTimeoutMS: 45000,
> serverSelectionTimeoutMS: 30000,
> family: 4, //
force IPv4
> })
> .then(() => {
> console.log(‘[Test]
MongoDB connected successfully with mongoose + family=4’);
> return mongoose.disconnect();
> })
> .then(() => {
> console.log(‘[Test]
Disconnected cleanly’);
> process.exit(0);
> })
> .catch((err) => {
> console.error(‘[Test]
MongoDB connection failed’);
> console.error(err);
> process.exit(1);
> });
> EOF
[Test] MONGODB_URI is SET
[Test]
MongoDB connection failed
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: Configure IP Access List Entries - Atlas - MongoDB Docs
at \_handleConnectionErrors (/app/node_modules/mongoose/lib/connection.js:897:11)
at NativeConnection.openUri (/app/node_modules/mongoose/lib/connection.js:848:11)
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:545:9)
at process.processTimers (node:internal/timers:519:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-vss5jy1-shard-00-01.e2frgbq.mongodb.net:27017' => \[ServerDescription\],
'ac-vss5jy1-shard-00-02.e2frgbq.mongodb.net:27017' => \[ServerDescription\],
'ac-vss5jy1-shard-00-00.e2frgbq.mongodb.net:27017' => \[ServerDescription\]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-kiio9q-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}