I am new to mongodb, but I’m working on a project which was using mongo and had created a large collection with a large number of documents. I was able to work with it no problem.
Today when I tried to start mongod I got the following error –
{"t":{"$date":"2024-11-01T15:29:16.827-07:00"},"s":"E", "c":"CONTROL", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
I looked and /data/db didn’t exist, so I created it.
Now I was able to start mongod, but the old collection I was working with is not showing up.
How can I fix this? It was 100s of GBs of collected data, did I lose it?
2
Answers
When you created the new data directory, MongoDB didn’t automatically migrate the existing data from the old directory. This is because MongoDB stores its data in a specific directory, and it expects the data to be in the correct format.
Most likely you started your MongoDB differently.
/data/db
is the default path when you don’t specify anystorage.dbPath
(or--dbpath
).Check your previous scripts how
mongod
was started and then start your MongoDB with the same dbPath – or copy the files to/data/db
folder.