mongod 和 mongo 命令在 Windows 10 上不起作用 [英] mongod and mongo commands not working on windows 10

查看:52
本文介绍了mongod 和 mongo 命令在 Windows 10 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Windows 10 操作系统上安装了 mongoDB.然后我尝试通过移动到某个目录并在 cmd 中键入 mongod --datapath=data 来将其数据库路径设置为某个目录,其中 data 是包含数据库的文件夹(我使用了相对路径,因为我在那个目录中).但是消息传来 mongod 是无法识别的命令.经过一番搜索,我发现通过指定 mongod 路径,即 "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --datapath=data 有效.mongo 也发生了类似的事情.

I've installed mongoDB on my windows 10 OS. Then I tried setting its database path to some directory by moving to it and typing mongod --datapath=data in cmd, where data is the folder which is to contain the db(I've used the relative path because I'm in that directory). But message comes that mongod is unrecognized command. After some searching I found that by specifying mongod path, i.e. "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --datapath=data works. Similar thing happens for mongo.

我想直接运行mongodmongo命令,我见过有人直接用的(不用去目录也不指定路径)

I want to directly run mongod and mongo commands, I have seen people directly using it(without going to the directory or specifying the path).

推荐答案

对于 Windows 安装,默认情况下您必须使用 exe 的完整路径,除非您将其添加到 PATH.

For a Windows installation, by default you have to use the full path to the exe unless you add it to the PATH.

要将其添加到 PATH:

To add it to the PATH:

01) 获取 bin 的路径,例如:C:\Program Files\MongoDB\Server\4.0\bin
02) 按Windows键,输入env,选择编辑系统环境变量
03)Advanced 选项卡上,单击 Environment Variables
04)User variables for xxxx 部分,选择 path,然后单击 Edit... 按钮
05) 点击 New 并用斜杠粘贴你的路径,例如:
C:\Program Files\MongoDB\Server\4.0\bin\
06) 单击 OKOKOK 并重新启动命令窗口.
来源

01) Get path to bin, something like: C:\Program Files\MongoDB\Server\4.0\bin
02) Press the Windows key, type env, select Edit the system environment variables
03) On the Advanced tab, click Environment Variables
04) In the User variables for xxxx section, select path and then click the Edit... button
05) Click New and paste your path with a trailing slash, eg:
C:\Program Files\MongoDB\Server\4.0\bin\
06) Click OK, OK, OK and restart your command window.
Source

您看到的示例可能基于 UNIX 安装,我认为默认情况下将 mongo 作为服务安装(Windows 没有),这就是这些示例中的名称.

The examples you have seen are probably based on UNIX installations which I think by default install mongo as a service (which Windows doesn't) and that is what is called in those examples.

为了简化 Windows 上的启动和配置,您还可以将其安装为服务.请参阅 Mongo 文档 此处 和为 MongoDB 配置 Windows 服务"部分.

To simplify startup and configuration on Windows, you can also install it as a service. See the Mongo documentation here and the "Configure Windows Service for MongoDB' section".

这将允许您通过简单地调用

This will then allow you to start and stop Mongo by simply calling

net start MongoDB

或者

net stop MongoDB

这篇关于mongod 和 mongo 命令在 Windows 10 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆