Trying to install mongoose to my node.js application, and all the time I am getting this error, tried changing everything including changing the IP to "Allow access from everywhere" My current IP is whitlisted as wellm still don’t know why getting the error.
const express = require('express');
const mongoose = require('mongoose');
const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');
const app = express();
mongoose.set('debug', true);
mongoose.connect("mongodb+srv://username:[email protected]/myDatabase?retryWrites=true&w=majority", {
serverSelectionTimeoutMS: 5000 // Set a timeout limit for connection attempts
})
.then(() => console.log("Connected to MongoDB Atlas"))
.catch(err => console.error("Connection error:", err));
This is the error I am getting
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: https://www.mongodb.com/docs/atlas/security-whitelist/
at _handleConnectionErrors (/Users/adityaverma/Desktop/trying ass8/node_modules/mongoose/lib/connection.js:909:11)
at NativeConnection.openUri (/Users/adityaverma/Desktop/trying ass8/node_modules/mongoose/lib/connection.js:860:11) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
‘mongo8-shard-00-02.hu8hm.mongodb.net:27017’ => ServerDescription {
address: ‘mongo8-shard-00-02.hu8hm.mongodb.net:27017’,
type: ‘Unknown’,
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
minRoundTripTime: 0,
lastUpdateTime: 791219720,
lastWriteDate: 0,
error: MongoNetworkError: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
at connectionFailureError (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:356:20)
at TLSSocket.<anonymous> (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:272:44)
at Object.onceWrapper (node:events:628:26)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: [Error: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
] {
library: 'SSL routines',
reason: 'tlsv1 alert internal error',
code: 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR'
}
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
maxMessageSizeBytes: null,
maxWriteBatchSize: null,
maxBsonObjectSize: null,
primary: null,
me: null,
'$clusterTime': null
},
'mongo8-shard-00-00.hu8hm.mongodb.net:27017' => ServerDescription {
address: 'mongo8-shard-00-00.hu8hm.mongodb.net:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
minRoundTripTime: 0,
lastUpdateTime: 791219875,
lastWriteDate: 0,
error: MongoNetworkError: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
at connectionFailureError (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:356:20)
at TLSSocket.<anonymous> (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:272:44)
at Object.onceWrapper (node:events:628:26)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: [Error: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
] {
library: 'SSL routines',
reason: 'tlsv1 alert internal error',
code: 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR'
}
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
maxMessageSizeBytes: null,
maxWriteBatchSize: null,
maxBsonObjectSize: null,
primary: null,
me: null,
'$clusterTime': null
},
'mongo8-shard-00-01.hu8hm.mongodb.net:27017' => ServerDescription {
address: 'mongo8-shard-00-01.hu8hm.mongodb.net:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
minRoundTripTime: 0,
lastUpdateTime: 791219524,
lastWriteDate: 0,
error: MongoNetworkError: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
at connectionFailureError (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:356:20)
at TLSSocket.<anonymous> (/Users/adityaverma/Desktop/trying ass8/node_modules/mongodb/lib/cmap/connect.js:272:44)
at Object.onceWrapper (node:events:628:26)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: [Error: 409CBCD701000000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 80
] {
library: 'SSL routines',
reason: 'tlsv1 alert internal error',
code: 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR'
}
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
maxMessageSizeBytes: null,
maxWriteBatchSize: null,
maxBsonObjectSize: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-9q7qfy-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
Node.js v18.16.0
2
Answers
Use basic code to connect the mongoose instead of complex code , if it does work tell me.
Try to whitelist your IP address from MongoDB Atlas. Use below steps to do it.
( Enter 0.0.0.0/0 as the IP address )