Basically I am using a hosting service called ventraIP for hosting my nodejs application. The application works just fine in my local machine but when I try to host it on the servers it throws the following error:
returncode: 0
stdout:
> aussies-backend@1.0.0 start /home/webnappc/aussiesbackend0
> node app.js
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://docs.atlas.mongodb.com/security-whitelist/
at NativeConnection.Connection.openUri (/home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/connection.js:832:32)
at /home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/index.js:345:10
at /home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose._promiseOrCallback (/home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/index.js:1135:10)
at Mongoose.connect (/home/webnappc/nodevenv/aussiesbackend0/12/lib/node_modules/mongoose/lib/index.js:344:20)
at Object.<anonymous> (/home/webnappc/aussiesbackend0/app.js:74:5)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map {
'cluster0-shard-00-02.gycrz.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-00.gycrz.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-01.gycrz.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
stderr:
npm WARN lifecycle The node binary used for scripts is /home/webnappc/nodevenv/aussiesbackend0/12/bin/node but npm is using /opt/alt/alt-nodejs12/root/usr/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
I have whitelisted all the IPs in my mongodb cluster’s network access tab (it is 0.0.0.0/0) so this is not an issue for sure.
When I open the terminal in my hosted server’s cPanel and type:
curl portquiz.net:27017
I am getting this:
[webnappc@s312 ~]$ curl portquiz.net:27017
curl: (7) Failed connect to portquiz.net:27017; Connection refused
[webnappc@s312 ~]$
I contacted the technical support team to open this specific port and they replied me with this:
Unfortunately, we cannot open ports. However, we can whitelist your specific IP address for either inbound or outbound.
Let us know what specific IP address you would like for either inbound or outbound.
Then I asked them to whitelist the ip addresses mentioned in these articles:
https://docs.atlas.mongodb.com/setup-cluster-security#required-outbound-access
https://docs.atlas.mongodb.com/setup-cluster-security#required-inbound-access
They said they have whitelisted the IPs but still I am facing the same issue.