MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect EC

时间:2024-03-25 13:16:07

已安装 mongodb ,但没有启动 mongodb 服务器。

第一步:打开CMD,进入到mongodb 的 bin目录

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect EC

第二步:输入指令:mongod --dbpath 数据库路径

若成功,则显示如下:

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect EC

第三步:刚才的窗口不要关,重新再打开一个cmd

再次进入到mongodb的bin目录下,并输入mongo,显示如下:

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect EC

 

 

最后就可以再控制台运行mongo程序了。例如:

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect EC