28

I tried to install mongoDB on my macbook air.

I've downloaded zipped file from official website and extract that file and move to root directory. After that, under that directory, I've made /data/db and /log folder.

Here is my mongodb.config which describes the basic config for my DB.

dbpath = /mongodb/data/db
logpath = /mongodb/log/mongo.log
logappend = true
#bind ip = 127.0.0.1
port = 27017

fork = true
rest = true
verbose = true
#auth = true
#noauth = true

Additionally, I want to know what the # means in the config file.

I put this file to /mongodb/bin, /mongodb is the directory I extracted the files into.

I opened terminal and entered ./mongod --config mongodb.config and I got this back.

Juneyoung-ui-MacBook-Air:bin juneyoungoh$ ./mongod --config mongodb.config
about to fork child process, waiting until server is ready for connections.
forked process: 1775
all output going to: /mongodb/log/mongo.log
ERROR: child process failed, exited with error number 100

How can I handle this error and what this means?

3
  • 1
    # begins a comment. Anything after a # in a line will be ignored.
    – 000
    Apr 12, 2013 at 5:08
  • 1
    Could you post what's in /mongodb/log/mongo.log? (if there's anything)
    – shelman
    Apr 12, 2013 at 21:08
  • @shelman Thanks for asking me. But somehow now my mongodb just working fine.-_-^ I got no clue. and log is too long to paste here. anyway, thanks again :D Apr 14, 2013 at 6:04

10 Answers 10

35

The data folders you created were very likely created with sudo, yes? They are owned by root and are not writable by your normal user. If you are the only user of your macbook, then change the ownership of the directories to you:

sudo chown juneyoungoh /data
sudo chown juneyoungoh /data/db
sudo chown juneyoungoh /data/log

If you plan on installing this on a public machine or somewhere legit, then read more about mongo security practices elsewhere. I'll just get you running on your macbook.

4
  • thanks for kind answer. But it didn't work. like below I already own these directories and files \n Juneyoung-ui-MacBook-Air:mongodb juneyoungoh$ ls -l total 120 -rw-r--r--@ 1 juneyoungoh staff 34520 3 23 05:09 GNU-AGPL-3.0 -rw-r--r--@ 1 juneyoungoh staff 1359 3 23 05:09 README -rw-r--r--@ 1 juneyoungoh staff 18436 3 23 05:09 THIRD-PARTY-NOTICES drwxr-xr-x@ 18 juneyoungoh staff 612 4 12 13:37 bin drwxr-xr-x 3 juneyoungoh staff 102 4 11 14:53 config drwxr-xr-x 10 juneyoungoh staff 340 4 11 14:28 data drwxr-xr-x 3 juneyoungoh staff 102 4 11 14:53 log Apr 12, 2013 at 7:17
  • That doesn't look like ls on /. Is that ~?
    – 000
    Apr 12, 2013 at 13:22
  • Thanks. I don't know why, but it works now. I didn't do anything. maybe the "chown" command changes something. thanks for you kind and wise answers. :D Apr 14, 2013 at 6:06
  • If he was already started the process, mongodb will refuse to start, I guess because it will be overwriting files already own by root. So he should purge the directories (dbpath and logpath) before restarting.
    – user12582392
    Nov 2, 2020 at 9:51
14

I had a similar issue and it was not related to any 'sudo' problem. I was trying to recover from a kernel panic!

When I look at my data folder I found out a mongod.lock file was there. In my case this page helped a lot: http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/. As they explain,

if the mongod.lock is not a zero-byte file, then mongod will refuse to start.

I tested this solution in my environment and it works perfectly:

  1. Remove mongod.lock file.
  2. Repair the database: mongod --dbpath /your/db/path --repair
  3. Run mongod: mongod --dbpath /your/db/path
2
  • just check the mongod.lock is not 0 byte, remove it, restart service, then everything work perfectly, Cheers man! Mar 13, 2017 at 2:26
  • great post mate!
    – user12582392
    Nov 2, 2020 at 9:52
9

There was the same problem on my machine. In the log file was:

Mon Jul 29 09:57:13.689 [initandlisten] ERROR: Insufficient free space for journal file
Mon Jul 29 09:57:13.689 [initandlisten] Please make at least 3379MB available in /var/mongoexp/rs2/journal or use --smallfiles

It was solved by using mongod --smallfiles. Or if you start mongod with --config option than in a configuration file disable write-ahead journaling by nojournal=true (remove the beginning #). Some more disk space would also solve the above problem.

0
4

It's because you probably didn't shutdown mongodb properly and you are not starting mongodb the right way. According your mongodb.config, you have dbpath = /mongodb/data/db - so I assume you created the repository /mongodb/data/db? Let me clarify all the steps.

  1. TO START MONGODB

In your mongodb.config change the dbpath = /mongodb/data/db to dbpath = /data/db. On your terminal create the db repository by typing: mkdir /data/db. Now you have a repository - you can start your mongo.

To start mongo in the background type: mongod --dbpath /data/db --fork --logpath /dev/null.

  • /data/db is the location of the db.
  • --fork means you want to start mongo in the background - deamon.
  • --logpath /dev/null means you don't want to log - you can change that by replacing /dev/null to a path like /var/log/mongo.log

    1. TO SHUTDOWN MONGODB

Connect to your mongo by typing: mongo and then use admin and db.shutdownServer(). Like explain in mongoDB

If this technique doesn't work for some reason you can always kill the process.

Find the mongodb process PID by typing: lsof -i:27017 assuming your mongodb is running on port 27017

Type kill <PID>, replace <PID> by the value you found the previous command.

3

Similar issue with the same error - I was trying to run the repair script sudo -u mongodb mongod -f /etc/mongodb.conf --repair

Checked ps aux | grep mongo and see that the daemon was running. Stopped it and then the repair script run without an issue.

Hope that could be helpful for someone else.

1
  • 1
    Using homebrew mongodb on Mac OS X I had to use mongod -f /usr/local/Cellar/mongodb/2.4.6/mongod.conf --repair (check your version, 2.4.6 might not be current for you). This fixed my issue. Thanks.
    – three
    Sep 20, 2013 at 13:14
2

I had the same error on linux (Centos) and this worked for me

  1. Remove mongod.lock from the dbpath

    $ rm /var/lib/mongo/mongod.lock

  2. Repair the mongod process

    $ mongod --repair

  3. Run mongod config

    $ mongod --config /etc/mongod.conf

1
  • yep i had to do the step 1 and then to remove /tmp/mongodb-27017.sock
    – Bill
    May 23, 2018 at 12:26
0

I had the same error. I ran it interactively to see the log.

2014-10-21T10:12:35.418-0400 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017

Then I used lsof to find out which process was using my port.

$ lsof -i:27017
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  2106 MYUSERID   10u  IPv4 0x635b71ec3b65b4a1      0t0  TCP *:27017 (LISTEN)

It was a mongod that I had forked previously and forgot to turn off (since I hadn't seen it running in my bash window). Simply killing it by running kill 2106, enabled my process to run without the error 100.

0

Generally, this error comes when the mongod.conf file is not able to find a certain path for Database store or log store or maybe processid store or maybe it's not getting the file permission to access the config directories and files which has been declared in mongod.conf

to resolve this error we need to observe the log generated by the MongoDB it will clearly indicate whether which file or directory you MongoDB is not able to access

the above error may look like below screenshot enter image description here

enter image description here

3
  • Thanks for replying to the old post. At the moment, I post this question I was so new with Linux so how to handle permission denied. The practical solution is using chown, but your answer shows how to track the error using log. Aug 16, 2018 at 0:56
  • if u are just doing practice on local machine use below command to change the directory premission Aug 18, 2018 at 8:27
  • you can use below command to change the permission of the directory chmod -R 777 /var/mongoprocess -R option will change permission recursively for all the files and directories Aug 18, 2018 at 8:31
0

create folder "data" and "db" inside it, in "/" path of your server. actually you should create or modify permissions of folder that the data is going to be stored!

0

My issue was that I ran out of space for my VM. Had to remove some old images and the issue was gone.

I had this in my logs

...
fatal log failure: No space left on device
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.