MongoDB 的默认数据库路径是什么?

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

What is the default database path for MongoDB?

mongodb

提问by holys

I got an error about dbpath (/data/db/) does not exist, but /etc/mongodb.confnamed it dbpath = /var/lib/mongodb. So, which is the default dbpath for MongoDB?

我收到了一个关于 的错误dbpath (/data/db/) does not exist,但/etc/mongodb.conf将其命名dbpath = /var/lib/mongodb. 为 MongoDB 的默认 dbpath 是什么?

回答by Stennie

The default dbpath for mongodb is /data/db.

mongodb 的默认 dbpath 是/data/db.

There is no default config file, so you will either need to specify this when starting mongodwith:

没有默认配置文件,因此您需要在开始时指定mongod

 mongod --config /etc/mongodb.conf

.. or use a packaged install of MongoDB (such as for Redhator Debian/Ubuntu) which will include a config file path in the service definition.

.. 或使用 MongoDB 的打包安装(例如RedhatDebian/Ubuntu),它将在服务定义中包含配置文件路径。

Note: to check the dbpath and command-line options for a running mongod, connect via the mongoshell and run:

注意:要检查正在运行的 dbpath 和命令行选项mongod,请通过mongoshell连接并运行:

db.serverCmdLineOpts()

In particular, if a custom dbpathis set it will be the value of:

特别是,如果dbpath设置了自定义,它将是以下值:

db.serverCmdLineOpts().parsed.dbpath           // MongoDB 2.4 and older
db.serverCmdLineOpts().parsed.storage.dbPath   // MongoDB 2.6+

回答by HeatfanJohn

I have version 2.0.7 installed on Ubuntu and it defaulted to /var/lib/mongodb/and that is also what was placed into my /etc/mongodb.conffile.

我在 Ubuntu 上安装了 2.0.7 版,它默认为 2.0.7 版,这/var/lib/mongodb/也是放入我的/etc/mongodb.conf文件中的内容。

回答by Abhi

For a Windows machine start the mongodprocess by specifying the dbpath:

对于 Windows 机器,mongod通过指定 dbpath启动进程:

mongod --dbpath \mongodb\data

Reference: Manage mongodProcesses

参考:管理mongod流程

回答by Sammaye

I depends on the version and the distro.

我取决于版本和发行版。

For example the default download pre-2.2 from the MongoDB site uses: /data/dbbut the Ubuntu install at one point used to use: var/lib/mongodb.

例如,从 MongoDB 站点下载 2.2 之前的默认下载使用:/data/db但 Ubuntu 安装曾经使用过:var/lib/mongodb

I think these have been standardised now so that 2.2+ will only use data/dbwhether it comes from direct download on the site or from the repos.

我认为这些现在已经标准化,因此 2.2+ 将只使用data/db它来自网站上的直接下载还是来自 repos。

回答by The Red Pea

The Windows x64 installer shows the a path in the installer UI/wizard.

Windows x64 安装程序在安装程序 UI/向导中显示路径。

You can confirm which path it used later, by opening your mongod.cfgfile. My mongod.cfgwas located here C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg(change for your version of MongoDB!

您可以通过打开mongod.cfg文件来确认它稍后使用的路径。我的mongod.cfg位于此处C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg(根据您的 MongoDB 版本进行更改!

When I opened my mongd.cfgI found this line, showing the default db path:

当我打开我的mongd.cfg我发现这一行,显示默认的数据库路径:

dbPath: C:\Program Files\MongoDB\Server.0\data

However, this caused an error when trying to run mongod, which was still expecting to find C:\data\db:

但是,这在尝试运行时导致了错误mongod,它仍然期望找到C:\data\db

2019-05-05T09:32:36.084-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating

2019-05-05T09:32:36.084-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating

You could pass mongoda --dbpath=...parameter. In my case:

你可以传递mongod一个--dbpath=...参数。就我而言:

mongod --dbpath="C:\Program Files\MongoDB\Server.0\data"