Hello Fellow Codenewbies 👋
It was all started with the lack of space for C: drive on my computer. Finally, to make more space in the C: drive, I decided to move all projects and personal folders to the D: drive.
And then the time came when I wanted to continue one of my NodeJS with MongoDB project.
When I run
mongod, it threw me
shutting down with code: 100 error as below.
I faced chains of errors afterward.
I've Googled only to find plenty of results to fix the errors with either Linux or macOS and barely found anything for Windows 10.
I had two choices:
- Uninstall and re-install MongoDB with a new database path
- Go through a series of trials and errors to adapt the steps that need to be done with Linux or macOS to Windows 10
As painful as it is, I've chosen the second way so I could help others who want to do the same.
Without further ado, below is how I did it.
What I Want To Achieve
- Move existing MongoDB databases from C: to D: drive
- Store future databases in D: drive
How I Achieved It
- Make sure that
mongoddoesn't run in the background. If it still runs, you can close it with
ctrl + c.
- Create a folder named
dbin D: drive (or any other location that you prefer)
Run this command in Windows PowerShell (Admin)
Change the path to where you created your new data folder and make sure that you put the path inside the quote.
ctrl + c
- Copy/cut & paste existing data from data folder in drive C: to D:
- Make sure that the
mongod.lockfile is empty. Otherwise, you can delete it. This won't damage anything and will be automatically regenerated when you run
mongod. (When it's not empty, it will throw an error &
mongodwill automatically shut down.)
✔ Your existing data now should have been moved and you can start to get your data stored in the new directory when you work with one.
This post is one of my TIL notes based on my own research and experience.