Hello Fellow Codenewbies š,
It all started with my computer's lack of space for C: drive.
Finally, I moved all projects and personal folders to the D: drive to make more space in the C: drive.
And then, the time came when I wanted to continue one of my NodeJS with MongoDB projects.
When I run mongod
, it throws me a 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 saw 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 Linux or macOS steps for Windows 10.
As painful as it is, I've chosen the second way so I can 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
mongod
doesn't run in the background. You can close it withctrl + c
if it still runs. - Create a folder named
data
with subfolderdb
in D: drive (or any other location that you prefer) -
Run this command in Windows PowerShell (Admin)
mongod --dbpath="D:\data\db"
Change the path to where you created your new data folder, and make sure you put the path inside the quote.
Exit
mongod
withctrl + c
Copy/cut & paste existing data from the data folder in drive C: to D:
Make sure that the
mongod.lock
file is empty. Otherwise, you can delete it. This step won't damage anything and will be automatically regenerated when you runmongod
. (When it's not empty, it will throw an error &mongod
will 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.
Thank you for reading!
Last, you can find me on Twitter. Let's connect! š