如何更改MongoDB保存数据的位置

时间:2014-01-17 21:55:40

标签: macos mongodb

我在我的mac上安装了mongodb但是,正如我现在所看到的,我使用root权限安装它,它在系统启动时启动。每当我尝试使用mongod --dbpath更改默认数据文件夹的位置时,我会收到以下错误:

[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

当我运行lsof -i 4 -a时,我看到mongo使用了27017。另一个用于mongo的web进程(我假设)。我尝试使用端口号lsof -i tcp来终止进程,但它没有帮助。当我尝试改变路径时,同样的事情发生了。我不知道该做什么,因为我必须将数据存储在外部硬盘上。

2 个答案:

答案 0 :(得分:2)

我终于解决了这个问题。我不得不使用macports停止这个过程:

sudo port unload mongodb

然后我跑了

mongod --dbpath /new/path/

答案 1 :(得分:1)

是的,您可以在data

中提供mongo.cfg文件夹路径
path_to_your_mongo_db\mongodb\bin\mongod.exe --dbpath custom_path\data

有关完整配置,请参阅here

编辑:适用于Mac

mongod --dbpath <some alternate directory>

您可以参考here了解详情

有关更多配置,您可以查看此topic

重要提示: 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.

相关问题