Reputation: 458
I have a basic script which is test for connecting to database.
When I'm trying to run the script with node Connection.js
the script's run, but I don't receive the response in console that successfully connected to the database
and as well with that I don't receive any error. It's just looks like the script runs but nothing happens.
On VPS I'm using Ubuntu 18.04. I allowed the IP address and port from my local machine.
Any ideas what's wrong with this one, I was trying to find anything related this topic but unsuccessful
Connection.js
const mongoose = require('mongoose');
var express = require('express');
const router = express.Router();
// this is our MongoDB database
const dbRoute =
'mongodb://username:[email protected]:22/CryptoCurrencies';
mongoose.Promise = global.Promise;
// connects our back end code with the database
mongoose.connect(dbRoute, {
useNewUrlParser: true,
useUnifiedTopology: true
});
let db = mongoose.connection;
db.once('open', () => console.log('connected to the database'));
EDIT1
I edited the code and I 100% sure that I allow on my ubuntu server port 22
but I still can't connect to my VPS with Node
I receive this error - (node:10115) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED
Any ideas on how I can fix this one? Username and password are correct, DB name is also correct, ip address and port as well. Currently I totally don't understand what is wrong. I check tons of resources to solve that and just connect my NodeJS script from local machine to VPS server.
Upvotes: 4
Views: 1353
Reputation: 646
There seems to be some issues with the configuration on server. Please go through these checklist for issues.
bind_ip = 127.0.0.1
for local only, bind_ip = 0.0.0.0
to listen traffic from all network interfaces.) for more details.CryptoCurrencies
the one you are connecting to)Check this link on how to configure auth on MongoDB server instance https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac
Upvotes: 5
Reputation: 66
I'm kind of sure your VPS must have the port 22 bound to openssh-server... Are you sure you've been able to start mongod correctly and it's listening on port 22?
BTW, all services under 1024 are kind of standardized you should always try to use ports above 1024.
Could you share with us the configuration of your mongod?
Upvotes: 3