【发布时间】:2017-05-07 16:13:52
【问题描述】:
当我尝试连接 node.js 应用程序时,我得到:
MongoError:连接 0 到 127.0.0.1:27017 已关闭
var MongoClient = require('mongodb').MongoClient
,format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
if(err) throw err;
var collection = db.collection('student');
collection.insert({id:4,name:shyam}, function(err, docs) {
collection.count(function(err, count) {
console.log(format("count = %s", count));
});
// Locate all the entries using find
collection.find().toArray(function(err, results) {
console.dir(results);
// Let's close the db
db.close();
});
});
})
【问题讨论】:
-
mongodb 是否在你的本地机器上运行?
-
没有。当我尝试启动服务然后得到错误 1053:服务没有及时响应启动或控制请求。 Windows 无法在本地计算机上启动 mongodb 服务。
-
这些问题需要查看monodb日志