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.