MongoDB has set the dbpath incorrectly

Hello. I’m using Ubuntu 18.04, and I encountered an error while updating MongoDB from version 4 to 6.

My original dbpath was set to /var/lib/mongodb, but after the update, a /data/db directory was created, and it seems to have become the new dbpath. As a result, MongoDB fails to start.

I also noticed that a mongod.conf.dpkg-dist file was created, but it doesn’t seem to have any significant differences. I’ve tried running the following command, but it still fails:

mongod --config /etc/mongod.conf

Could you please help me identify the cause of this issue? Thank you.

When you start mongod without any parameters it will try to start on default dirpath /data/db
Are you showing us the correct log?
When you ran with configfile it will choose the values defined in the config file
Check your mongod.log for this run.It will show more details
Its location will be that is defined in your config file

What are the differences between the “mongod command” in mongod and the “log” in MongoDB?

In mongod.log, it refers to /var/lib/mongodb as the dbpath, while in mongod command, it specifies /data/db as the dbpath.

It is already clarified above
When you run mongod without any params it will choose default port 27017 and default dbpath /data/db
If dbpath /data/db exists it will come up else it fails
When you run mongd with config file it chooses whatever values you have defined in the config file
So as per your mongod.log it is using correct db path
From where you got the above snapshot which is showing dbpath as /data/db
Did you try to run just mongod?
From your mongod.log what does it show after the path.Did it come up or failed?