我正在尝试在我的本地机器上连接mongodb&使用下面的代码, 但它正在给出时间错误。
app.js->
// import the language driver
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
var ObjectID = require('mongodb').ObjectID;
// Connection URL
var url = 'mongodb://127.0.0.1:27017/testdb';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
//ensure we've connected
assert.equal(null, err);
console.log("Connected correctly to server");
//close the database connection
return db.close();
});
错误追踪:
C:\Users\AmitRuwali\git\myfinancenew>node app.js
Failed to load c++ bson extension, using pure JS version
C:\Users\AmitRuwali\git\myfinancenew\node_modules\mongodb\lib\mongodb\mongo_clie
nt.js:378
throw err
^
AssertionError: null == { err: 'connection to [127.0.0.1:27017] timed out' }
at C:\Users\AmitRuwali\git\myfinancenew\app.js:13:10
at C:\Users\AmitRuwali\git\myfinancenew\node_modules\mongodb\lib\mongodb\mon
go_client.js:375:11
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
我的Mongodb服务器在localhost中正常运行,我可以查询db&使用mongo客户端完美收藏。
我需要有关此超时问题的帮助。
感谢。
答案 0 :(得分:0)
先试试
mongod -repair
mongod start
mongo
而不是启动你的应用
如果您正在使用Windows,请打开mongoDB数据库服务器,然后输入这3行,然后尝试启动您的应用
如果它不起作用,请卸载,然后再使用npm
再次安装mongo答案 1 :(得分:0)
问题已解决,版本中存在问题, 我在下面的URL中做了以下的事情并且它有效。
Node MongoDb { err: 'connection to [127.0.0.1:27017] timed out' }
$ npm uninstall mongodb --save
$ npm install mongodb --save