1

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?

JFly28
  • 101
  • 2
  • 9

3 Answers3

3

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

JFly28
  • 101
  • 2
  • 9
0

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

Community
  • 1
  • 1
  • I have read most of the posts and comments however I am not able to change the **'default'** location of the database. Referring to this article on the mongodb website, [https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/]. they do not mention how to change this behavior. so I'm still in need of answers. – JFly28 Jan 17 '19 at 02:30
0

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

A. El Idrissi
  • 487
  • 7
  • 7