Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Last active August 29, 2015 14:01
Show Gist options
  • Save mattcanty/72a041f00aad51a1a973 to your computer and use it in GitHub Desktop.
Save mattcanty/72a041f00aad51a1a973 to your computer and use it in GitHub Desktop.
mongodump
net stop MongoDB
rmdir C:\data\db /S /Q
mkdir C:\data\db
net start MongoDB
mongorestore
rmdir dump /S /Q
@mattcanty
Copy link
Author

This assumes that you are running MongoDB as a service in Windows.
Create a new directory which is not in the MongoDB data directory.
Save this file into the new directory and run it.

Steps with some verbosity

  1. Dump database contents to current directory
  2. Stop MongoDB service
  3. Remove the database data directory - plus recursive deletion of subdirectories and done quietly (/Q)
  4. Create the directory again
  5. Start MongoDB service
  6. Call mongorestore which will re-populate the database
  7. Remove the dump directory! All clean and ready to go again

@mattcanty
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment