MongoDB Node.js 模块“mongo”未被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42159481/
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-02 17:59:37  来源:igfitidea点击:

MongoDB Node.js module 'mongo' is not recognised as an internal or external command

node.jsmongodb

提问by alex351

I am following Node.js tutorials by Code Academy from Youtube and am currently on video number 19. There you can see at 3:10 he typed mongo and then it switched to the database.

我正在关注来自 Youtube 的 Code Academy 的 Node.js 教程,目前正在播放第 19 号视频。在那里你可以看到在 3:10 他输入了 mongo,然后它切换到了数据库。

But in my case its giving the following error 'mongo' is not recognized as an internal or external command, operable program or batch file.Why is this happening?

但在我的情况下,它给出了以下错误'mongo' is not recognized as an internal or external command, operable program or batch file.为什么会发生这种情况?

I followed the steps exactly as shown in the video. To throw a light, in my case, its connected to the database and 2 documents are inserted (as shown). But in next step its giving this error. Please help me devs.

我完全按照视频中显示的步骤操作。举个例子,在我的例子中,它连接到数据库并插入了 2 个文档(如图所示)。但在下一步它给出了这个错误。请帮助我开发人员。

回答by alex351

You have to add the mongo executable to PATH, so the commands are accessible from outside the MongoDB bin folder.

您必须将 mongo 可执行文件添加到 PATH,以便可以从 MongoDB bin 文件夹外部访问这些命令。

Search for your MongoDb installation bin folder and copy the path (e.g.: C:\Program Files\MongoDB\bin) Right click My Computer > Properties > Advanced system settings > Environment Variables > System variables > Look for "Path" > Edit > New > Paste in the path to your Mongodb bin folder > Restart your terminal

搜索您的 MongoDb 安装 bin 文件夹并复制路径(例如:C:\Program Files\MongoDB\bin)右键单击我的电脑 > 属性 > 高级系统设置 > 环境变量 > 系统变量 > 查找“路径”> 编辑 > 新建> 粘贴到你的 Mongodb bin 文件夹的路径 > 重启你的终端

EDIT:

编辑:

A faster way to get to the Environment Variables is to press Start on Windows and type "env"and then select "Edit environment variables"or "Edit system variables". No need really, to set the Path system wide if you don't have the privileges.

访问环境变量的更快方法是在 Windows 上按“开始”并键入“env”,然后选择“编辑环境变量”“编辑系统变量”。如果您没有权限,则无需真正设置 Path 系统。

EDIT 2:

编辑2:

As some have stated, the path of mongo from version 4.0 changed a little: C:\Program Files\MongoDB\Server\4.0\bin

正如一些人所说,mongo 从 4.0 版开始的路径发生了一些变化:C:\Program Files\MongoDB\Server\4.0\bin

回答by anyapps

If you use Windows you need to add mogo (C:\Program Files\MongoDB\Server\4.0\bin) to PATH Env then close terminal and open again.....mongo --version should work

如果您使用 Windows,则需要将 mogo (C:\Program Files\MongoDB\Server\4.0\bin) 添加到 PATH Env 然后关闭终端并再次打开.....mongo --version 应该可以工作

回答by Darush

Make sure you have install mongodb software. You can download the software for your operating system using the following official link:

确保您已安装 mongodb 软件。您可以使用以下官方链接下载适用于您的操作系统的软件:

https://docs.mongodb.com/manual/installation/

https://docs.mongodb.com/manual/installation/

For windows users, follow the instructions of the following official link:

对于windows用户,请按照以下官方链接的说明进行操作:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

回答by Anmol Mittal

First of all , "mongo" is not a node.js module.

首先,“mongo”不是 node.js 模块。

'mongo' is not recognized as an internal or external command,    operable program or batch file.

This error is because your system doesnt recognize the command "mongo"

此错误是因为您的系统无法识别命令“mongo”

If you want to connect to database from terminal/cmd, check that the database path is included in your environment variable and then run command "mongo", or open the directory where mongodb is installed and access it from there

如果您想从终端/cmd 连接到数据库,请检查您的环境变量中是否包含数据库路径,然后运行命令“mongo”,或者打开安装 mongodb 的目录并从那里访问它