0

I am doing doing a project where I have a mongo database on a debian VM 9.8.0 (with last virtualbox version). I have a nodejs app on my computer (Windows 10) and I want to connect this application to my mongo database. I tried a lot of things but still get the same error : Error : connect ECONNREFUSED :217017

  • I tried to disable firewall on my computer and on the VM
  • I tried all VM network conf possible (currently on private host network)
  • I can ping my VM from my computer and from my computer to the VM
  • The application is working with a mongo database in local
  • Probably a bad config somewhere, the code seems correct
  • The mongod service is running with the command : sudo service mongod start
  • I can see that mongod is in LISTENING state by using lsof -i

nodejs server : (launched with "node server.js" command)

var fs = require('fs');
var url = require('url');
var querystring = require('querystring');

var express = require('express');
var app = express();

//****** MONGODB *******/
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const urlMongo = 'mongodb://192.168.56.101:27017';

// Database Name
const dbName = 'projet';

// Create a new MongoClient
const client = new MongoClient(urlMongo);

error :

AssertionError [ERR_ASSERTION]: { Error: connect ECONNREFUSED 192.168.56.101:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
  errn... == null
    at D:\Basile\Master Informatique\BDD\Projet\server.js:134:20
    at err (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\utils.js:411:14)
    at executeCallback (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\utils.js:401:25)
    at err (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\operations\mongo_client_ops.js:285:21)
    at connectCallback (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\operations\mongo_client_ops.js:265:5)
    at server.connect (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\operations\mongo_client_ops.js:353:14)
    at Server.<anonymous> (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb\lib\topologies\server.js:237:11)
    at Object.onceWrapper (events.js:277:13)
    at Server.emit (events.js:189:13)
    at Pool.<anonymous> (D:\Basile\Master Informatique\BDD\Projet\node_modules\mongodb-core\lib\topologies\server.js:452:12)

Since the application is running with a local mongo db, I do not understand why it is not running well with my VM.

Noskyra
  • 1
  • 1
  • You could be running something currently on this port are you? Make sure your MongoDB instance is running using mongod. – smitty_werbenjagermanjensen Apr 17 '19 at 20:12
  • I checked that nothing was already running on this port and I'm sure that mongod is on. I am running mongod in a ssh session and I can see that the service is here by using lsof -i :( – Noskyra Apr 18 '19 at 07:10
  • Just to be sure, I did a netcat -a in my cmd and I saw that 127.0.0.1:27017 was in LISTENING state, does that mean that the port is already used ? – Noskyra Apr 18 '19 at 07:35
  • A listening state for a port just means it is waiting for a connection. You ca try : ps -elf | grep mongo to see if its running. Alternativley please make sure that MongoDB is started sudo service mongod start – smitty_werbenjagermanjensen Apr 18 '19 at 12:48

0 Answers0