Mac 上 mongodb 数据库的位置

我对 Mac 和 Mongodb 都是新手。

我有一个奇怪的疑问,访问数据库创建使用 mongodb 的 Mac?

我知道,在 windows 中有一个名为 c: datadb 的文件夹,我的数据库文件存储在那里。

数据库在 Mac 中的存储方式和位置。

我记得我做过类似

sudo mkdir -p /data/db
sudo chown `id -u` /data/db

在 Mac 上创建这样一个文件夹,但是我没有在这个文件夹中找到任何数据库文件,尽管我创建了一个数据库。

Mac 上的数据库文件保存在哪里?

如果你能帮忙,我将不胜感激。

132422 次浏览

The default data directory for MongoDB is /data/db.

This can be overridden by a dbpath option specified on the command line or in a configuration file.

If you install MongoDB via a package manager such as Homebrew or MacPorts these installs typically create a default data directory other than /data/db and set the dbpath in a configuration file.

If a dbpath was provided to mongod on startup you can check the value in the mongo shell:

db.serverCmdLineOpts()

You would see a value like:

"parsed" : {
"dbpath" : "/usr/local/data"
},

If MongoDB is installed on macOS via Homebrew, the default data directory depends on the type of processor in the system.

Intel Processor Apple M1 Processor
Data Directory /usr/local/var/mongodb /opt/homebrew/var/mongodb
Configuration file /usr/local/etc/mongod.conf /opt/homebrew/etc/mongod.conf
Log directory /usr/local/var/log/mongodb /opt/homebrew/var/log/mongodb

Run brew --prefix to see where Homebrew installed these files.

See the MongoDB "Install on macOS" documentation for additional details.

Thanks @Mark, I keep forgetting this again and again. After installing MongoDB with Homebrew:

  • The databases are stored in the /usr/local/var/mongodb/ directory
  • The mongod.conf file is here: /usr/local/etc/mongod.conf
  • The mongo logs can be found at /usr/local/var/log/mongodb/
  • The mongo binaries are here: /usr/local/Cellar/mongodb/[version]/bin

I have just installed mongodb 3.4 with homebrew.(brew install mongodb) It looks for /data/db by default.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

Here is the output of mongod execution.

I had the same problem, with version 3.4.2

to run it (if you installed it with homebrew) run the process like this:

$ mongod --dbpath /usr/local/var/mongodb

Env: macOS Mojave 10.14.4

Install: homebrew

Location:/usr/local/Cellar/mongodb/4.0.3_1

Note :If update version by brew upgrade mongo,the folder 4.0.4_1 will be removed and replace with the new version folder