Skip to content

Instantly share code, notes, and snippets.

@lucien144
Last active February 1, 2018 05:54
Show Gist options
  • Save lucien144/d7b2901df5cd98f94815ca37f8a9f91e to your computer and use it in GitHub Desktop.
Save lucien144/d7b2901df5cd98f94815ca37f8a9f91e to your computer and use it in GitHub Desktop.
Basic MongoDB commands
# Create new database & new collection
use new_db
db.new_db.save({test: 'test'});
# Create root user
use admin
db.createUser(
{
user: "root",
pwd: "*******",
roles: ["root"]
}
)
# Creates new user with access to one database only
use new_db
db.createUser(
{
user: "new_db",
pwd: "*************",
roles: ["readWrite"]
}
);
mongo -u root -p --authenticationDatabase admin
> use admin
> db.createUser(
> {
> user: "backup",
> pwd: "************",
> roles: ["backup"]
> }
> );
mongodump -u backup -p *********** --out /var/backups/mongobackups/`date +"%m-%d-%y"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment