1

I installed mongodb on my mac but, as I can see now, I installed it using root privileges and it starts on system startup. Whenever I try to change the location of the default data folder using mongod --dbpath I get the following set of errors:

[initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
[initandlisten] ERROR:   addr already in use
[websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:28017
[initandlisten] now exiting
[websvr] ERROR:   addr already in use

When I run lsof -i 4 -a I see that 27017 is used by mongo. The other one is used for web processes of mongo (I assume). I tried to kill the processes by using port number lsof -i tcp but it doesn't help. When I try to change path the same thing happens. I don't know what to do at this point because I have to store data on external hard drive.

Anastasia
  • 864
  • 5
  • 13
  • 26

2 Answers2

3

I finally resolved the issue. I had to stop the process using macports:

sudo port unload mongodb

and then I ran

mongod --dbpath /new/path/
Anastasia
  • 864
  • 5
  • 13
  • 26
  • The part that was giving me trouble was how to stop mongodb because I couldn't kill it via terminal. I explained I used mongod --dbpath in the second sentence but the command didn't work because mongo was running. Sorry if it was not clear! – Anastasia Jan 18 '14 at 07:54
  • I assumed that you have already stopped mongodb. Since, you cannot do that operation without stop. This is common thing for all kind of this things like mysql, postgresql, etc.. – Hüseyin BABAL Jan 18 '14 at 07:58
1

Yes, you can give data folder path in your mongo.cfg

path_to_your_mongo_db\mongodb\bin\mongod.exe --dbpath custom_path\data

For full configuration please refer here

Edit: For Mac

mongod --dbpath <some alternate directory>

You can refer here for full detail

For more configuration, you can have a look at this topic

Important: Whether using the default /data/db/ or an alternate directory, ensure that the user account running mongod has read and write permissions to the directory.

Community
  • 1
  • 1
Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
  • I don't have cfg file and I am using mac. The point is that mongo starts with the system and once it's started I can't stop it so any of the commands in the tutorial by mongo are not working – Anastasia Jan 17 '14 at 22:16