Cheatography
https://cheatography.com
General Commands
show databases |
Show all databases |
use <database> |
Select a database for usage |
show collections |
Show all collections in a database |
db |
Shortcut to the currently used database |
db.<collection>.remove() |
Truncate (empty) a collection |
Update where all documents with field matches
db.<collection>.update({
storeID: ObjectId("<id_here>")
},
{
$set: {
storeID: ObjectId("<id_here>")
}
},
{
multi: true
})
|
The multi allows multiple documents to be updated. If you do not specify $set it will remove all other fields but the one you specified changes to, do not forget to use $set
|
|
Rename Database
db.copyDatabase('old_name', 'new_name'); |
Copy the database to a new database |
use <old_name> |
Switch to the database you wish to delete |
db.dropDatabase(); |
Destroys the selected database |
There is no native way to rename a database, use these commands together to accomplish this.
Export and Import Databases
mongodump -d <database_name> -o <directory_backup> -h <host> --port <port> -u <user> -p |
mongorestore <directior_backup> |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment