34

I have installed mongodb for mac os through 10gen and I have gone through the documentation to do so. Everything seems fine apart from the configuration file. I can not see it in /etc/mongod.config. Do I have to manually create this config file? And if so how can I go about it?

cheers

Rob Schneider
  • 679
  • 4
  • 13
  • 27

4 Answers4

85

The default path for brew installed mongodb on Mac OS X is /usr/local/etc/mongod.conf

René Höhle
  • 26,716
  • 22
  • 73
  • 82
Addison
  • 851
  • 1
  • 6
  • 2
  • This is correct, please ignore the above answer which says there is no default – Joshua Glazer Sep 05 '13 at 22:45
  • The original question mentions installing through 10gen (MongoDB) which may or may not be using Brew (at the time the question was written, it was more likely a [manual installation](http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/#manual-installation). If you are installing via a package manager (such as apt, yum, brew, ...) the package maintainer will decide where the config file should live and what it should be called. The other answers are correct that if you just start `mongod` there is no baked in default config file path. – Stennie Dec 11 '13 at 15:24
  • 2
    Unfortunately this is only used with the --config arg. – HankCa Apr 17 '15 at 23:14
27

Unless you have installed a packaged version of MongoDB (for example, using Homebrew or Mac Ports) you will have to create a config file manually, or just pass the appropriate command line parameters when starting up MongoDB.

If you want a commented example of a config file to start with, the mongodb.conf in the Debian/Ubuntu package should be a good starting point. Important options to check are the dbpath and logpath which will likely be different for you.

It would also be worth looking at the Homebrew mongodb formula which includes setting up a LaunchAgent script to manage the mongod service.

Stennie
  • 63,885
  • 14
  • 149
  • 175
  • 5
    It is also worth noting that `mongod` doesn't look for a default config file - you do have to pass the `-f ...` or `--config ...` [parameter](http://www.mongodb.org/display/DOCS/File+Based+Configuration) whether starting via command line or as part of the service wrapper (eg. LaunchAgent plist). – Stennie Jul 22 '12 at 12:46
  • Thanks for your respond, I am very new to OSX and have no Idea how to create a new file. I just searched google and one website suggested to do it through Automator! Is that the way or is there any easier way? Also dbpath the path to the parent directory of mongodb installed folder ? which in my case it is extracted in /users/[MyDirectory/Mongodb-osc-86_64.2.0.6 ? – Rob Schneider Jul 22 '12 at 13:07
  • @user1460625: If you are just getting started it's probably easier to hold off on setting up LaunchAgent and config files, and just start mongod from a command line in Terminal (eg `/path/to/mongod`). That would start a MongoDB server using all defaults. The default data path is `/data/db` but you can specify a different directory with `-dbpath /path/to/data`. The [Using MongoDB from 10gen builds](http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/#using-mongodb-from-10gen-builds) doc has instructions including these steps. – Stennie Jul 22 '12 at 13:28
  • 1
    @user1460625: if you do want to edit files, it's probably easiest to use TextEdit (comes with OS X). An important note: TextEdit usually defaults to "rich" format which includes fonts etc which you don't want for a config file. You can turn this off for a document by choosing "Make Plain Text" from the "Format" menu. You can tell which mode you are in because a plain text document won't have a formatting toolbar or ruler at the top of the document. So you would create a new file in TextEdit, paste & edit the sample mongodb.conf, save, then run `mongod --config /path/to/mongod.conf`. – Stennie Jul 22 '12 at 13:33
  • @Timwi: Updated the link to point to the 2.4 mongodb.conf as an example. The previous link was to the master branch in github, which has recently renamed the packaged config to [mongod.conf](https://github.com/mongodb/mongo/blob/master/debian/mongod.conf) in the 2.5 dev releases. – Stennie Dec 11 '13 at 13:39
  • Let future visitors to this answer beware, mongo 2.6.1+ have moved to a YAML based config file syntax. See http://docs.mongodb.org/manual/reference/configuration-options/#config-file-format – a p Jun 09 '14 at 21:14
  • 1
    @ap: MongoDB 2.6 *added* a YAML-based configuration format, but (as per the note on the page you linked) the previous format is still supported for backward compatibility. – Stennie Jun 09 '14 at 23:15
11

Yes, unless you install via a package manager (like apt or yum on Linux) you have to create this manually. Then, When you start mongod you simply need to specify where the config file is, for example:

./mongod -f /path/to/mongod.conf

For how that file should look, just take a look here:

http://docs.mongodb.org/manual/reference/configuration-options/

You can also see the aforementioned Linux config files from the packages on github:

https://github.com/mongodb/mongo/blob/master/rpm/mongod.conf

https://github.com/mongodb/mongo/blob/master/debian/mongodb.conf

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Adam Comerford
  • 21,336
  • 4
  • 65
  • 85
0

In the case you installed MongoDB without Homebrew, i.e. downloaded the TGZ package directly from MongoDB Download Center, you will can add the configuration file:

sudo nano /etc/mongod.conf

Please use only spaces (no tabs) in the file and leave a space after the key. For example:

security:
  authorization: enabled
net:
  port: 27017
  bindIp: 0.0.0.0

And then run the instance with the configuration flag:

mongod -f /etc/mongod.conf

I wrote a post about installing MongoDB Community Edition directly from the TGZ archive.

LineDrop
  • 461
  • 4
  • 5