MongoDB
FAQ: How to "vacuum" or "compact" a database?
Deleted documents are not removed from disk. Use the repairDatabase()
command to reclaim this space:
$ mongo mydb
> db.repairDatabase()
Note:
- This is a blocking operation.
- It (temporarily) requires at least as much space as the database itself to run. (See below for how to dump/restore if you need to workaround this.)
HOWTO: Delete (drop) a database?
$ mongo beebo_dev
> db.dropDatabase()
FAQ: How to backup and restore a database?
Backup (mongodb needs to be running):
# creates "backup" directory, backs up all databases managed by MongoDB
$ sudo mongodump -o backup
Restore (mongodb needs to be running):
# restore
$ sudo mongorestore backup
If you are dumping and restoring so you're able to db.repairDatabase()
(which temporarily requires twice the size of the database itself) follow
these steps:
# backup as above
$ sudo mongodump -o backup
# stop the server
$ sudo stop mongodb
# delete database files
# restart the server
$ sudo start mongodb
# restore as above
$ sudo mongorestore backup
See backups.
FAQ: What's the difference between mongodump and mongoexport?
It seems that the only real difference is output file format; see
SERVER-203. (mongorestore
reads the mongodump format.)