mongoDB 错误:错误:无法连接到 [localhost:27017]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22290143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:37:36  来源:igfitidea点击:

mongoDB error: Error: failed to connect to [localhost:27017]

mongodb

提问by user13476

I'm trying to install habitrpglocally but I keep getting a mongoDB error after typing node src/seed.js:

我正在尝试在本地安装habirrpg,但在输入后我不断收到mongoDB错误node src/seed.js

Error: failed to connect to [localhost:27017]

I saw on other questions with the same error people have suggested typing in 'mongod' and that fixes it by creating a local server. I get the error:

我在其他问题上看到了同样的错误,人们建议输入“mongod”并通过创建本地服务器来修复它。我收到错误:

-bash: mongod: command not found

Can't figure out what's wrong. Any ideas?

无法弄清楚出了什么问题。有任何想法吗?

回答by Shubham Shinde

  1. Open CMD (In Windows) or terminal (In Ubuntu).

  2. type command >cd PATH_FOR_MONGODB_BIN_FOLDER

    cd C:\Program Files\MongoDB\Server\3.2\bin

    for ubuntu command will be same :

    cd /home/MongoDB/Server/3.2/bin

  3. then type command >mongod --dbpath PATH_FOR_DATA_FOLDER

    mongod --dbpath C:\data\db

    For ubuntu command will be :

    ./mongod --dbpath /home/data/db

    you can specify any folder as data folder.

  4. Wait till CMD or Terminal shows "waiting for connections"

    2016-09-01T21:38:33.170+0530 I NETWORK [initandlisten] waiting for connections on port 27017

  5. Then open new CMD or terminal window.

  6. type command >cd PATH_FOR_MONGODB_BIN_FOLDER ( same as step 3 )

    cd C:\Program Files\MongoDB\Server\3.2\bin

    Don't close previous window of cmd or teminal.

  7. then run mongodb by typing "mongo" in windows or "./mongo" in ubuntu

    mongo

    For ubuntu

    ./mongo

  8. After mongodb run successfully you can close previous CMD window.

  1. 打开 CMD(在 Windows 中)或终端(在 Ubuntu 中)。

  2. 键入命令 >cd PATH_FOR_MONGODB_BIN_FOLDER

    cd C:\Program Files\MongoDB\Server\3.2\bin

    对于 ubuntu 命令将是相同的:

    cd /home/MongoDB/Server/3.2/bin

  3. 然后输入命令 >mongod --dbpath PATH_FOR_DATA_FOLDER

    mongod --dbpath C:\data\db

    对于 ubuntu 命令将是:

    ./mongod --dbpath /home/data/db

    您可以指定任何文件夹作为数据文件夹。

  4. 等到 CMD 或终端显示“等待连接”

    2016-09-01T21:38:33.170+0530 I NETWORK [initandlisten] 等待端口 27017 上的连接

  5. 然后打开新的 CMD 或终端窗口。

  6. 键入命令 >cd PATH_FOR_MONGODB_BIN_FOLDER(与步骤 3 相同)

    cd C:\Program Files\MongoDB\Server\3.2\bin

    不要关闭 cmd 或终端的前一个窗口。

  7. 然后通过在 Windows 中键入“mongo”或在 ubuntu 中键入“./mongo”来运行 mongodb

    蒙戈

    对于 ubuntu

    ./蒙戈

  8. mongodb 运行成功后,您可以关闭之前的 CMD 窗口。

回答by SomeKittens

You don't have MongoDB installed. Follow the directions for your system to install it: http://docs.mongodb.org/manual/installation/

您没有安装 MongoDB。按照您系统的说明进行安装:http: //docs.mongodb.org/manual/installation/

From the habitRPG docs:

来自习惯RPG文档:

Before starting make sure to have MongoDB, NodeJS and npm and Git installed and set up.

在开始之前,请确保安装并设置了 MongoDB、NodeJS 和 npm 以及 Git。

回答by Adolfo F. Ibarra Landeo

I think that you don't have an environmental variable declared. Assuming that your MongoDB installation is C:\ProgramFiles\MongoDB\Server\YOUR_VERSION_NUMBER\, you should just add the binfolder path of that version of MongoDB to your PATH system environment variable.

我认为您没有声明环境变量。假设您的 MongoDB 安装是C:\ProgramFiles\MongoDB\Server\YOUR_VERSION_NUMBER\,您应该只bin将该版本的 MongoDB的文件夹路径添加到您的 PATH 系统环境变量中。

Here's a link where you can find the way to do that without complications : http://www.computerhope.com/issues/ch000549.htm

这是一个链接,您可以在其中找到没有并发症的方法:http: //www.computerhope.com/issues/ch000549.htm

回答by Adittya Verma

I got this issue because I didn't have MongoDB. SO Installed MongoDB and tried to run node application and it worked.

我遇到这个问题是因为我没有 MongoDB。所以安装了 MongoDB 并尝试运行节点应用程序并且它工作正常。

If you don't have MongoDB then follow below steps to install and enjoy

如果您没有 MongoDB,请按照以下步骤安装并享受

Commands :

命令:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

$ sudo apt-get update

$ sudo apt-get install -y mongodb-org

then type mongo in terminal and if you will get console for mongo then its done.

然后在终端中输入 mongo ,如果你会得到 mongo 的控制台,那么它就完成了。

回答by Abdelhalim FELLAGUE CHEBRA

After installing MongoDb you have to add the directory "data\db" under the C:\ directory, then you should start the mongod.exe

安装完MongoDb后需要在C:\目录下添加data\db目录,然后启动mongod.exe