database 我如何知道 mongoDB 在哪里存储数据?(它不在默认的 /data/db 中!)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7247474/
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
How can I tell where mongoDB is storing data? (its not in the default /data/db!)
提问by Zugwalt
My host came with a mongodb instance and there is no /db directory so now I am wondering what I can do to find out where the data is actually being stored.
我的主机带有一个 mongodb 实例,但没有 /db 目录,所以现在我想知道我能做些什么来找出数据的实际存储位置。
采纳答案by EhevuTov
mongoddefaults the database location to /data/db/.
mongod默认数据库位置为/data/db/.
If you run ps -xa | grep mongodand you don't see a --dbpathwhich explicitly tells mongodto look at that parameter for the db location and you don't have a dbpathin your mongodb.conf, then the default location will be: /data/db/and you should look there.
如果你运行ps -xa | grep mongod,你看不到--dbpath它明确告诉mongod看看该参数为DB的位置和你没有dbpath在你的mongodb.conf,那么默认位置是:/data/db/你应该看看那里。
回答by Tomasz Nurkiewicz
What does your configuration file say?
你的配置文件说什么?
$ grep dbpath /etc/mongodb.conf
If it is not correct, try this, your database files will be present on the list:
如果不正确,请尝试此操作,您的数据库文件将出现在列表中:
$ sudo lsof -p `ps aux | grep mongodb | head -n1 | tr -s ' ' | cut -d' ' -f 2` | grep REG
It's /var/lib/mongodb/*on my default installation (Ubuntu 11.04).
它/var/lib/mongodb/*在我的默认安装(Ubuntu 11.04)上。
Note that there is also a /var/lib/mongodb/mongod.lockfile holding mongodPID for convenience, however it is located in the data directory - which we are looking for...
请注意,为了方便起见,还有一个/var/lib/mongodb/mongod.lock保存mongodPID的文件,但它位于数据目录中 - 我们正在寻找...
回答by Mwirabua Tim
In the newer version of mongodb v2.6.4 try:
在较新版本的 mongodb v2.6.4 中尝试:
grep dbpath /etc/mongod.conf
It will give you something like this:
它会给你这样的东西:
dbpath=/var/lib/mongodb
And that is where it stores the data.
这就是它存储数据的地方。
回答by Robotnik
While this question is targeted for Linux/Unix instances of Mongo, it's one of the first search results regardless of the operating system used, so for future Windows users that find this:
虽然此问题针对 Mongo 的 Linux/Unix 实例,但无论使用何种操作系统,它都是第一个搜索结果之一,因此对于发现此问题的未来 Windows 用户:
If MongoDB is set up as a Windows Service in the default manner, you can usually find it by looking at the 'Path to executable' entry in the MongoDB Service's Properties:
如果 MongoDB 以默认方式设置为 Windows 服务,您通常可以通过查看 MongoDB 服务属性中的“可执行文件路径”条目来找到它:
回答by glock18
I find db.serverCmdLineOpts()the most robust way to find actual path if you can connect to the server. The "parsed.storage.dbPath" contains the path your server is currently using and is available both when it's taken from the config or from the command line arguments.
db.serverCmdLineOpts()如果您可以连接到服务器,我会找到最可靠的方法来查找实际路径。“parsed.storage.dbPath”包含您的服务器当前使用的路径,并且在从配置或命令行参数中获取时都可用。
Also in my case it was important to make sure that the config value reflects the actual value (i.e. config didn't change after the last restart), which isn't guaranteed by the solutions offered here.
同样在我的情况下,重要的是确保配置值反映实际值(即配置在上次重新启动后没有更改),此处提供的解决方案无法保证这一点。
db.serverCmdLineOpts()
Example output:
示例输出:
{
"argv" : [
// --
],
"parsed" : {
"config" : "/your-config",
"storage" : {
"dbPath" : "/your/actual/db/path",
// --
}
},
"ok" : 1.0
}
回答by zillabunny
From my experience the default location is /var/lib/mongodbafter I do
根据我的经验,默认位置是/var/lib/mongodb在我做之后
sudo apt-get install -y mongodb-org
回答by Achim Koellner
I found mine here on a OSX system /usr/local/var/mongodb
我在 OSX 系统 /usr/local/var/mongodb 上找到了我的
回答by Dibyendu Mitra Roy
For windows Go inside MongoDB\Server\4.0\bin folder and open mongod.cfg file in any text editor. Then locate the line that specifies the dbPath param. The line looks something similar
对于 Windows 进入 MongoDB\Server\4.0\bin 文件夹并在任何文本编辑器中打开 mongod.cfg 文件。然后找到指定 dbPath 参数的行。这条线看起来很相似
dbPath: D:\Program Files\MongoDB\Server\4.0\data
dbPath: D:\Program Files\MongoDB\Server\4.0\data
回答by Prashant Pokhriyal
Actually, the default directory where the mongod instance stores its data is
实际上,mongod 实例存储其数据的默认目录是
/data/dbon Linux and OS X,
/data/db在 Linux 和 OS X 上,
\data\dbon Windows
\data\db在 Windows 上
If you installed MongoDB using a package management system, check the /etc/mongod.conffile provided by your packages to see the directory is specified.
如果您使用包管理系统安装 MongoDB,请检查/etc/mongod.conf您的包提供的文件以查看指定的目录。
The storage.dbPathsetting is available only for mongod.
该storage.dbPath设置仅适用于mongod。
The Linux package init scripts do not expect storage.dbPathto change from the defaults. If you use the Linux packages and change storage.dbPath, you will have to use your own init scripts and disable the built-in scripts.
Linux 包初始化脚本不希望storage.dbPath更改默认值。如果您使用 Linux 软件包并更改storage.dbPath,则必须使用自己的 init 脚本并禁用内置脚本。
回答by Nilotpal
If you could somehow locate mongod.log and the do a grep over it
如果您能以某种方式找到 mongod.log 并对其进行 grep
grep dbpath mongod.log
The value for dbpath is the data location for mongodb!! All the best :)
dbpath 的值是 mongodb 的数据位置!!祝一切顺利 :)


