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
What is the default database path for MongoDB?
提问by holys
I got an error about dbpath (/data/db/) does not exist
, but /etc/mongodb.conf
named 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 mongod
with:
没有默认配置文件,因此您需要在开始时指定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 的打包安装(例如Redhat或Debian/Ubuntu),它将在服务定义中包含配置文件路径。
Note: to check the dbpath and command-line options for a running mongod
, connect via the mongo
shell and run:
注意:要检查正在运行的 dbpath 和命令行选项mongod
,请通过mongo
shell连接并运行:
db.serverCmdLineOpts()
In particular, if a custom dbpath
is 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.conf
file.
我在 Ubuntu 上安装了 2.0.7 版,它默认为 2.0.7 版,这/var/lib/mongodb/
也是放入我的/etc/mongodb.conf
文件中的内容。
回答by Abhi
For a Windows machine start the mongod
process by specifying the dbpath:
对于 Windows 机器,mongod
通过指定 dbpath启动进程:
mongod --dbpath \mongodb\data
Reference: Manage mongod
Processes
参考:管理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/db
but 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/db
whether 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.cfg
file. My mongod.cfg
was 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.cfg
I 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 mongod
a --dbpath=...
parameter. In my case:
你可以传递mongod
一个--dbpath=...
参数。就我而言:
mongod --dbpath="C:\Program Files\MongoDB\Server.0\data"