我正在做一个项目,其中在debian VM 9.8.0(具有最新的virtualbox版本)上具有mongo数据库。 我的计算机(Windows 10)上有一个nodejs应用程序,我想将此应用程序连接到mongo数据库。 我尝试了很多事情,但仍然遇到相同的错误: 错误:连接ECONNREFUSED:217017
nodejs服务器:(使用“ node server.js”命令启动)
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);
错误:
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)
由于该应用程序在本地mongo db上运行,因此我不明白为什么它在我的VM上无法正常运行。