如何在 Windows 7 中为 mongoDB 设置默认 dbpath? [英] How to set default dbpath for mongoDB in windows 7?

查看:90
本文介绍了如何在 Windows 7 中为 mongoDB 设置默认 dbpath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的 Windows 机器上安装了 mongoDB

I just installed mongoDB in my windows machine

MongoDB version       : Windows 64-bit 2008 R2+ release 3.0.4
OS Version            : Microsoft Windows 7 Ultimate 64-bit
Installation Directory: "C:\Program Files\MongoDB"

没有在默认的C:\data\db\中创建数据库,而是在安装目录下创建了一个目录,即C:\Program Files\MongoDB\data\db.现在我可以通过命令

instead of creating the database in default C:\data\db\, I created a directory in the installation directory, i.e. C:\Program Files\MongoDB\data\db. Now I can run mongod server by the command

mongod --dbpath "C:\Program Files\MongoDB\data\db"

如果我只运行 mongod 它会抛出一个异常说

If I run only mongod it throws an exception saying

[initandlisten] exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating

因此,显然默认的 dbpath 设置为 C:\data\db\.每次运行 mongod 都要显式指定 --dbpath

So, apparently the default dbpath is set to C:\data\db\. Each time I run mongod, I have to explicitly specify --dbpath

有没有办法覆盖默认的 dbpath 值?我试过按照 这个答案 解决问题.但是由于没有默认的 mongod.cfg 文件,现在我必须调整命令:

Is there a way to override the default dbpath value? I have tried following this answer, which solved the issue. But as there were no default mongod.cfg file, now I have to tun the command:

mongod --config "C:\Program Files\MongoDB\mongod.cfg"

这没有多大帮助,因为现在我每次都必须明确指定 --config.我想要做的只是输入 mongod,每次我想启动 mongo 服务器.这怎么办?

Which doesn't help much, because now I have to explicitly specify --config each time. All I want to do is just type mongod, each time I want to start mongo server. How can this be done?

推荐答案

你快接近了.Windows下可以将MongoDB安装为Service,官方文档安装章节 给出了如何完成这项工作的详细说明.

You are almost close. In Windows, MongoDB can be installed as Service, the installation chapter of official document gives detailed instruction on how to get that done.

您提到但是由于没有默认的 mongod.cfg 文件,现在我必须使用 --config 运行该命令".如果您成功地将 MongoDB 安装为服务,您就不必像那样启动和停止.命令如下:

You mentioned "But as there were no default mongod.cfg file, now I have to run the command with --config". If you successfully install the MongoDB as service, you don't have to start and stop like that. The command will be as following:

 net start MongoDB

 net stop MongoDB

其实,如果你不介意在windows启动时启动MongoDB,你也可以在Windows Service部分将MongoDB设置为自动启动服务.

Actually, if you don't mind starting MongoDB when windows starts, you can also set MongoDB as auto-start service in Windows Service part.

这篇关于如何在 Windows 7 中为 mongoDB 设置默认 dbpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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