要在Debian上更改MongoDB的存储路径,请按照以下步骤操作:
sudo systemctl stop mongodb
/mnt/new_storage:sudo mkdir -p /mnt/new_storage
mongodb):sudo chown -R mongodb:mongodb /mnt/new_storage
mongodump备份原始数据目录(默认情况下为/data/db):sudo mongodump --out /mnt/new_storage/backup
/etc/mongod.conf),找到storage.dbPath设置并更改为新的存储路径:sudo nano /etc/mongod.conf
将以下行:
storage:
dbPath: /data/db
更改为:
storage:
dbPath: /mnt/new_storage
保存并关闭配置文件。
使用mongorestore将备份的数据恢复到新的存储路径:
sudo mongorestore --dir /mnt/new_storage/backup
sudo systemctl start mongodb
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
在输出中,检查dbPath字段是否指向新的存储路径。
完成以上步骤后,MongoDB应该已经成功更改了存储路径。