尝试连接到 mongodb 服务器时无法识别 mongod 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15053893/
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
mongod command not recognized when trying to connect to a mongodb server
提问by Kristian82
I am following the tutorials at docs.mongodb.org, I have completed the first tutorial which was to install mongodb on a windows machine. I am now at the second stage which is getting started with mongodb development. I am stuck at the first stage of this section which instructs me to type "mongo" into a system prompt. When I do this I simply get an error message saying the following 'mongo' is not recognized as an internal or external command, operable program or batch file
. I know this is probably something quite simple that I am doing wrong, does anyone have any ideas?
我正在学习 docs.mongodb.org 上的教程,我已经完成了在 Windows 机器上安装 mongodb 的第一个教程。我现在处于 mongodb 开发入门的第二阶段。我被困在本节的第一阶段,它指示我在系统提示中键入“mongo”。当我这样做时,我只会收到一条错误消息,内容如下'mongo' is not recognized as an internal or external command, operable program or batch file
。我知道这可能是我做错的很简单的事情,有人有任何想法吗?
采纳答案by br3w5
You need to run mongod
first in one cmd window then open another and type mongo
. Make sure you updated your Windows Path environment variable too so that you don't have to navigate to the directory you have all of the mongo binaries in to start the application. To update the Path variable:
您需要mongod
先在一个 cmd 窗口中运行,然后再打开另一个窗口并输入mongo
. 确保你也更新了你的 Windows Path 环境变量,这样你就不必导航到所有 mongo 二进制文件所在的目录来启动应用程序。要更新 Path 变量:
Go to Control Panel > System & Security > System > Advanced System Settings > Environment Variables > navigate to the Path variable hit Edit and add ;C:\mongodb
to the Path (or whatever the directory name is where MongoDB is located (the semi-colon delimits each directory).
转到控制面板 > 系统和安全 > 系统 > 高级系统设置 > 环境变量 > 导航到路径变量点击编辑并添加;C:\mongodb
到路径(或任何目录名称是 MongoDB 所在的位置(分号分隔每个目录) .
回答by Travis Heeter
You need to add Mongo's bin
folder to the "Path" Environment Variable
您需要将 Mongo 的bin
文件夹添加到“Path”环境变量中
Here's how on Windows 10:
以下是在 Windows 10 上的操作:
Find Mongo's binfolder.
If you're not sure where it is, it's probably in
C:\Program Files\MongoDB\Server\3.4\
. It should look like this:Copy the path to the bin folder. It should be
C:\Program Files\MongoDB\Server\3.4\bin\
Press win, type
env
, Windows will suggest "Edit the System Environment Variables", click that.On the Advanced tab, click "Environment Variables"
Highlight the "Path" variable, click "Edit":
This will bring up the "Edit environment variable" window, click "New"
This will start a new line in the list of folders:
Paste your path to the bin folder. Make sure it ends with a
\
like so:Press "OK", "OK", "OK"
Now you should be able to run
mongod
andmongo
from anywhere in a command window.
找到 Mongo 的bin文件夹。
如果您不确定它在哪里,它可能在
C:\Program Files\MongoDB\Server\3.4\
. 它应该是这样的:将路径复制到 bin 文件夹。它应该是
C:\Program Files\MongoDB\Server\3.4\bin\
按win,键入
env
,Windows 会提示“编辑系统环境变量”,单击它。在高级选项卡上,单击“环境变量”
突出显示“路径”变量,单击“编辑”:
这将打开“编辑环境变量”窗口,单击“新建”
这将在文件夹列表中开始一个新行:
将您的路径粘贴到 bin 文件夹。确保它以这样的结尾
\
:按“确定”、“确定”、“确定”
现在您应该能够在命令窗口中的任何位置运行
mongod
和运行mongo
。
回答by dilion.dani
It is probably too late, but for the sake of others (like me) who faced the same problem. It is all about the little '\' at the end of the path variable. When you insert the path to MongoDB's bin directory at the end of the PATH windows variable, do not forget to put the '\' (Backslash) at the end, which tells windows it is a directory and not an executable named bin... e.g. I:\Program Files\MongoDB\Server\3.0\bin\
这可能为时已晚,但为了其他面临同样问题的人(如我)。这都是关于路径变量末尾的小“\”。当你在 PATH windows 变量的末尾插入 MongoDB 的 bin 目录的路径时,不要忘记在末尾加上 '\'(反斜杠),它告诉 windows 它是一个目录而不是一个名为 bin 的可执行文件......例如 I:\Program Files\MongoDB\Server\3.0\bin \
回答by Sajidur Rahman
Seems like, The environmental variable is not correctly set up.
好像,环境变量设置不正确。
Go to the mongodb installation folder and get the executable files (mongo.exe, mongod.exe etc) location. (In my case) Something like :
转到 mongodb 安装文件夹并获取可执行文件(mongo.exe、mongod.exe 等)位置。(就我而言)类似于:
C:\Program Files\MongoDB\Server.2\bin
Then go to :
然后去:
Panel > System & Security > System > Advanced System Settings > Environment Variables
Find the PATH
variable and edit its value. Then add C:\Program Files\MongoDB\Server\3.2\bin
and don't forget to separate each values with ;
. Now confirm and exit.
找到PATH
变量并编辑其值。然后添加C:\Program Files\MongoDB\Server\3.2\bin
,不要忘记用;
. 现在确认并退出。
回答by reza.cse08
For add environment variable please add \after bin like below
要添加环境变量,请在 bin 后添加\,如下所示
C:\Program Files\MongoDB\Server.2\bin\
Then try below code in command prompt to run mongo server from parent folder of data folder.
然后在命令提示符下尝试以下代码以从数据文件夹的父文件夹运行 mongo 服务器。
mongod -dbpath ./data
For my case I am unable to run mongo from command prompt(normal mode). You should run as administrator. It also works on git bash.
对于我的情况,我无法从命令提示符(正常模式)运行 mongo。您应该以管理员身份运行。它也适用于 git bash。
回答by Sara
Are you sure that you have specified the correct paths?
您确定您指定了正确的路径吗?
You need to be in the right directory, i.e.
您需要在正确的目录中,即
C:\Program Files\MongoDB\bin
and the path you are installing into needs to be the correct one
并且您要安装到的路径需要是正确的
i.e.
IE
mongod --dbpath
C:\Users\Name\Documents\myWebsites\nodetest1
A folder named "data" must also exist in your project folder.
项目文件夹中还必须存在名为“data”的文件夹。
I got the same error and this worked for me.
我遇到了同样的错误,这对我有用。
回答by Rare? Ghinga
This worked for me: .\mongod --dbpath c:......
这对我有用: .\mongod --dbpath c:......
回答by sanj singh
if still not working for you then just close all of your command prompts and then again open and run mongo, mongoimport, mongodb from anywhere it ll work because after setting the path variable command prompt should be restarted.
如果仍然不适合您,那么只需关闭所有命令提示符,然后再次打开并从任何地方运行 mongo、mongoimport、mongodb,因为在设置路径变量后应该重新启动命令提示符。
回答by xameeramir
Apart from having a Path
variable, the directory C:\data\db
is mandatory.
除了有一个Path
变量,目录C:\data\db
是强制性的。
Create this and the error shall be solved.
创建这个,错误将被解决。
回答by Amit Chawla
First, make sure you have the environment variable set up. 1. Right click on my computer 2. properties 3. advanced system settings 4. environment variables 5. edit the PATH variable. and add ;"C:\mongoDb\bin\" to the PATH variable.
首先,确保您已设置环境变量。1. 右键单击我的电脑 2. 属性 3. 高级系统设置 4. 环境变量 5. 编辑 PATH 变量。并将 ;"C:\mongoDb\bin\" 添加到 PATH 变量中。
Path in the quotes may differ depending on your installation directory. Do not forget the last '\' as it was the main problem in my case.
引号中的路径可能因您的安装目录而异。不要忘记最后一个'\',因为它是我的主要问题。