node.js - 在windows服务器配置了mongo数据库并已经开启,为什么mongoose依然无法连接?
怪我咯
怪我咯 2017-04-17 15:01:48
0
2
644

在windows服务器配置了mongo数据库并已经开启,为什么mongoose依然无法连接?

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var models = require('./models');
var db = mongoose.connect("mongodb://localhost:27017");
db.connection.on("error",function(err){
    console.log("链接失败"+err)
})
db.connection.on("open",function(){
    console.log("链接成功")
})

链接的时候提示fail to connect to server

前提是mongodb的服务是已经打开的

是因为win32的mongodb版本太低,还是因为其他原因?求指教

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
阿神

I also use nodejs in the window system, but I use express+mongoose. In order to facilitate opening the server, I slightly modified the code in bin/www:

var exec = require('child_process').exec;
exec('mongod --dbpath e:/mongodb/db', {
    cwd: 'e:/mongodb/bin'
});

Before starting the server, open a sub-process and let this sub-process start the mongodb service

小葫芦

Usually it still means that the mongodb server did not start normally. Please first check whether there is a mongod process running and whether port 27017 is listening.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template