JFly28
JFly28

Reputation: 101

Changing the location of mongo db in mac

So I tried to change the location of the 'default' location of monogo's database /data/db with this command in bash $ sudo mongo --dbpath /usr/local/<new folder> and it started right up, however after shutting down and trying start again I run $ mongod from bash it gives this error "I CONTROL [initandlisten] shutting down with code:100".

  1. My question is, do I have to type this --dbpath <directory> flag each time I want to use the database...?

  2. How do I let mongo know the 'default' directory is moved?

Upvotes: 1

Views: 5661

Answers (3)

A. El Idrissi
A. El Idrissi

Reputation: 487

Include an alias in your bash profile with the right dbpath.

  1. Edit this file: /Users/YOUR_NAME/.bash_profile

  2. add this line to the file: alias mongod="mongod --dbpath /usr/local/NEW_FOLDER"

  3. Save it.

  4. open a new terminal and start mongo typing: mongod

Upvotes: 0

JFly28
JFly28

Reputation: 101

So with and exhaustive searching and pouring through the documentation, I tried a lot of solutions and here is one I found that worked for me. 'This is a macOS solution'. Note: Rename '/what/ever/location' to your actual location, but I recommend keeping the data, db, bin, log.

When installing mongodb using homebrew (pre-requisites, install xcode).

$ brew install mongodb

The official documentation says it does not create a config file, so you have to create one and put in this location.

/etc/mongod.conf

Once created use your text editor( of choice) to insert this code. Mine is simplified, but mongo documentation has a complete list of what else to include. Mongo documentation storage options: Note: this code is written in .yaml or .yml so no tabs.

systemLog:
  destination: file
  path: "/what/ever/location/log/mongod.log"
  logAppend: true
storage:
  dbPath: "/what/ever/location/data/db"
  indexBuildRetry: true
  repairPath: "/what/ever/location/data/db/repairdb"
  journal:
    enabled: true
processManagement:
  fork: true
net:
  bindIp: 127.0.0.1
  port: 27017
setParameter:
  enableLocalhostAuthBypass: false

I put in some extra stuff like log and repair path it's your choice. Next alter your .bash_profile with this line:

# MongoDB Aliases
alias mongod="mongod --dbpath /what/ever/location/bin"

While you there if you haven't done so update your environment variable $PATH where the mongod shell is located.

export PATH="/what/ever/location/bin:$PATH"

In your cli (of choice) run this line to check if worked:

$ mongod

Upvotes: 3

Mark Heard
Mark Heard

Reputation: 1

Depending on your installation your mongod should have a mongod.conf file the specifies your default location --dbpath does not modify the config file. You will likely need to adjust permissions on the new db directory as well.

With out seeing the error codes I would recommend the following posts:

Changing Mongo Data Store

MongoDB Error Code 100

Upvotes: 0

Related Questions