I have developed a nodejs web server (api) that connects to mongodb database.
I set the mongodb NetworkAccess to be 0.0.0.0, meaning that it connects from evrywhere.
The server api is working fine without any isse from my local machine, and with free hosting on render.
Now I’m using a paid hosting on Plesk, and the server is refusing to connect: it give s me the following error from the Plesk CLI when I try to run the server:
npm run start
Process exited with non-zero exit code ‘1’
[email protected] start
node server
Server running on port 5000
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 (/var/www/vhosts/kws.tn/api.kws.tn/node_modules/mongoose/lib/connection.js:896:11)
at NativeConnection.openUri (/var/www/vhosts/kws.tn/api.kws.tn/node_modules/mongoose/lib/connection.js:847:11)
at async connectDB (/var/www/vhosts/kws.tn/api.kws.tn/config/db.js:5:18) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
‘cluster0-shard-00-02.c1aum.mongodb.net:27017’ => [ServerDescription],
‘cluster0-shard-00-01.c1aum.mongodb.net:27017’ => [ServerDescription],
‘cluster0-shard-00-00.c1aum.mongodb.net:27017’ => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-72cshk-shard-0’,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
I added the web server IP address to the list of NetworkAccess list on mongodb atals. but still the same issue.