Im getting an error while trying to connect to my MongoDB database, This is the repo .
This is the error I get while running the code -
MongoServerSelectionError: connection <monitor> to 52.20.9.178:27017 closed
at Timeout._onTimeout (C:\Users\PC\Downloads\SkyCrypt-development\SkyCrypt-development\node_modules\mongodb\lib\sdam\topology.js:306:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'cluster0-shard-00-00.kx9xv.mongodb.net:27017' => ServerDescription {
_hostAddress: HostAddress {
isIPv6: false,
host: 'cluster0-shard-00-00.kx9xv.mongodb.net',
port: 27017
},
address: 'cluster0-shard-00-00.kx9xv.mongodb.net:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 7396352,
lastWriteDate: 0,
error: MongoNetworkError: connection <monitor> to 52.20.9.178:27017 closed
at Connection.onClose (C:\Users\PC\Downloads\SkyCrypt-development\SkyCrypt-development\node_modules\mongodb\lib\cmap\connection.js:138:19)
at Socket.<anonymous> (C:\Users\PC\Downloads\SkyCrypt-development\SkyCrypt-development\node_modules\mongodb\lib\cmap\connection.js:65:46)
at Socket.emit (node:events:527:28)
at TCP.<anonymous> (node:net:709:12) {
[Symbol(errorLabels)]: Set(0) {}
}
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
I've tried whitelisting my ip and other stuff and it still wont work. can someone help me fix this?
I was facing same type of error <-- node_modules\mongodb\lib\cmap\connection.js:138:19) --->
I realized that in mongodb cluster I chose "Add current IP address" and when I edit it to "Allow access from Anywhere" my issue is resolved. Maybe this can resolve your issue.
Follow the path: Atlas-> Network Access -> IP Access List -> edit -> Allow Access from anywhere
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.