I have been struggling for this on for a few days. I recently bought a Raspberry Pi 400 and installed Ubuntu server 20.04.3 LTS. I have successfully set up mongoDB and can access it remotely. Now I want to change the location of the data being saved to a 500GB SSD plugged into the pi.
I have changed the mongod.conf file as below
# Where and how to store data.
storage:
# dbPath: /var/lib/mongodb
dbPath: /mnt/mongo/data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
As you can see I just changed the dbPath to a mounted drive.
Now to run mongod I have to run it with the command
mongod --dbpath=/mnt/mongo/data/
I have to fix a failed to unlink socket error using
sudo rm -rf /tmp/mongodb-27017.sock
Then I can connect fine on the PI but I can no longer connect remotely. I get error
Network is unreachable. Reason: couldn't connect to server 192.168.1.99:27017, connection attempt failed: SocketException: Error connecting to 192.168.1.99:27017 :: caused by :: Connection refused
I was under the impression that removing the /tmp/mongodb-27017.sock was the correct fix for that error and that mongo creates a new one on start up. I'm not sure if that is causing the problem with connecting remotely or I'm missing something when moving the default dbPath to the SSD.
How do I change the Mongo default db path and maintain the ability to access it remotely on Ubuntu server?
CodePudding user response:
Because you added only the --dbPath option the rest of settings are ignored. Best is to add all configuration settings in the mongodb.conf file and start the mongodb service with the config file as follow:
mongod --config mongod.conf