DEV Community

Cover image for How To Move Existing & Store Future Local MongoDB Data From One Drive To Another (Hard) Drive - Windows 10
Ayu Adiati
Ayu Adiati

Posted on • Edited on • Originally published at adiati.com

How To Move Existing & Store Future Local MongoDB Data From One Drive To Another (Hard) Drive - Windows 10

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.

mongod shutting down with code 100

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:

  1. Uninstall and re-install MongoDB with a new database path.
  2. 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

  1. Make sure that mongod doesn't run in the background. You can close it with ctrl + c if it still runs.
  2. Create a folder named data with subfolder db in D: drive (or any other location that you prefer)
  3. 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.

  4. Exit mongod with ctrl + c

  5. Copy/cut & paste existing data from the data folder in drive C: to D:

  6. 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 run mongod. (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! 😊

Top comments (0)