I'm using MongoDB 3.6.2 on openSUSE Tumbleweed. Today when I tried to open the mongo shell there was a connection error. When I checked the status of mongodb.service by using
sudo systemctl status mongodb
it showed
Active: failed
without too much useful information. Then I checked
sudo mongod --repair
I found the following error:
STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
So I went to check my /etc/mongodb.conf file and the storage part looks like the follows:
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine: mmapv1
# mmapv1:
# wiredTiger: true
and the network part looks like this:
net:
port: 27017
bindIp: 127.0.0.1,::1
ipv6: true
Other parts of this file unlikely caused this error so I omitted them.
I don't think I have ipv6 turned on on my machine but this shouldn't cause the error either because I tried to set
ipv6: false
it still did not work.
The problem is, I normally make mongodb as a service and enable it to start automatically at boot by
sudo systemctl start mongodb
sudo systemctl enable mongodb
And this worked fine until today. However, when I manually run
sudo mongod --dbpath /var/lib/mongodb --port 27017
it works correctly. So seems like mongodb still does not recognize the new dbpath /var/lib/mongodb. I did run
sudo mongod --config /etc/mongodb.conf
but looks like this did not help.
Please advise. Do I have to manually specify --dbpath every time? Can I continue to run mongodb as a service using the .conf file?
Thanks in advance.