MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
MongoNetworkError:首次连接时无法连接到服务器[本地主机:27017][错误:CONNECT ECONNREFUSED 127.0.0.1:27017
if i reinstall mongodb,the code works fine. i wanted an permenant solution
如果我重新安装MongoDB,代码运行得很好。我想要一个永久的解决方案
c[error:MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017 ]
C[错误:MongoNetWork错误:首次连接时无法连接到服务器[本地主机:27017][错误:CONNECT ECONNREFUSED 127.0.0.1:27017]
const mongoClient=require("mongodb").MongoClient
const state={
db:null
}
module.exports.connect=function(done){
const url="mongodb://localhost:27017"
const dbname="r-kart"
mongoClient.connect(url,(err,data)=>{
if(err) return done(err)
state.db=data.db(dbname)
done()
})
}
module.exports.get=function(){
return state.db
}
更多回答
Windows or Linux?
Windows还是Linux?
can you share mongod logs and OS version?
你能分享魔神日志和操作系统版本吗?
@WernfriedDomscheit windows
@WernFriedDomscheit窗口
@ROHITKHURANA mongodb-windows-x86_64-4.4.5-signed
@ROHITKHURANA MongoDB-Windows-x86_64-4.4.5-签名
优秀答案推荐
You can try:
Go to the control panel and select admins. tools.
click on "Services" and a list will appear.
look of MongoDB and right click and click on start.
你可以试一试:进入控制面板并选择Admins。工具。点击“服务”,将出现一个列表。查看MongoDB,然后右击并点击Start。
May be this work for you
也许这份工作适合你
更多回答
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。
我是一名优秀的程序员,十分优秀!