Cant change dbpath

I have a MongoDB image in a Kubernetes deployment and I’m trying to change the “dbpath” for my database. I’ve specified it in the /etc/mongod.conf file, but it doesn’t take the change:

# Where and how to store data.
dbPath: /tmp/mongo/db
enabled: true

When I check the paths, “/tmp/mongo/db” is empty, and /data/db remains the primary location. I also attempted to run “mongod --dbpath /tmp/mongo/db,” but it didn’t make any changes. I’ve noticed that one of the recommendations is to stop the mongod service to make this change, but I can’t do that in the Docker image.

Hello, welcome to the MongoDB community.

Yes, it is necessary to restart the service. You can manually move the data to the future path so as not to lose the data. If you don’t need to keep them, you can just change the path and restart.

You can restart the container.