Location of the mongodb database on mac

MacosMongodbOsx Lion

Macos Problem Overview


I am kind of new to mac as well as mongodb.

I have a weird doubt, accessing the database created using mongodb on mac?

I know, in windows there is a folder called c:\data\db, where my database files are stored.

How and where in mac, the database is stored.

I remember doing something like

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

to create such a folder on mac, but I didn't find any database file in this folder, though i created a database.

Where are the database files saved on mac?

Any help would be really appreciated.

Macos Solutions


Solution 1 - Macos

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.

Solution 2 - Macos

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

Solution 3 - Macos

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"
},

Solution 4 - Macos

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

Solution 5 - Macos

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.

Solution 6 - Macos

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpaniard89View Question on Stackoverflow
Solution 1 - MacosMark EdingtonView Answer on Stackoverflow
Solution 2 - MacossimonbogardeView Answer on Stackoverflow
Solution 3 - MacosStennieView Answer on Stackoverflow
Solution 4 - MacosRunnerdaveView Answer on Stackoverflow
Solution 5 - MacoscsonuryilmazView Answer on Stackoverflow
Solution 6 - MacosjyjinView Answer on Stackoverflow