问题如题。写了个小程序,突然之间就没有办法连上了,之前还可以的。
mongodb 和程序都是在本地mongodb 是用brew 安装的。网上查了好多,还是没找到原因,数据库的文件夹也重新删除过,还是不管用。求老司机指导,贴一下代码吧。
let mongoose = require("mongoose");
let utils = require("./utils");
var log4js = require('log4js');
//log the logger messages to a file, and the console ones as well.
log4js.configure({
appenders: [
{
type: "file",
filename: "log/trace_all.log",
},
{
type: "console"
}
],
replaceConsole: true
});
//regist model
require("./models/comment");
let CommentModel = mongoose.model("Comment");
mongoose.connect("mongodb://localhost:27017/acfun");
let db = mongoose.connection;
db.once("open", () => {
console.log("mongoose connect mongodb://localhost:27017/acfun success");
});
db.on("error", (err) => {
console.log(`db error : ${err}`);
setTimeout(()=>{
mongoose.connect("mongodb://localhost:27017/acfun");
},500);
});
数据库启动了嘛?