Skip to content

Instantly share code, notes, and snippets.

@romelperez
Last active August 28, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romelperez/16f669a813a65ab96412d2876da8394f to your computer and use it in GitHub Desktop.
Save romelperez/16f669a813a65ab96412d2876da8394f to your computer and use it in GitHub Desktop.
# backup
mongodump --db=mydb --archive=./backups/mydb.mongodump --authenticationDatabase=mydb -u username -p
# restore
mongorestore --drop --archive=./backups/mydb.mongodump --authenticationDatabase=mydb -u username -p
# export
mongoexport --db mydb --collection users --out ./test/fixtures/users.json --pretty --jsonArray
# import
mongoimport --db mydb --collection users --file ./test/fixtures/users.json --drop --jsonArray
use admin;
db.createUser({
user: 'superadmin',
pwd: '12345678',
roles: [ 'root' ]
});
use appdb;
db.createUser({
user: 'programmer',
pwd: '12345678',
roles: [{
db: 'appdb',
role: 'readWrite'
}]
});
db.auth('programmer', '12345678');
db.createCollection('users');
const usersList = [{
"_id" : ObjectId("5813bc184b57665d404678bc"),
"name" : "Pepe Pérez",
"email" : "pepeperez@gmail.com",
"pwd" : "11111111"
}, {
"_id" : ObjectId("5813bc184b57665d404678bd"),
"name" : "María Rodriguez",
"email" : "mariarodriguez@gmail.com",
"pwd" : "22222222"
}, {
"_id" : ObjectId("5813bc184b57665d404678be"),
"name" : "Carlos Martínez",
"email" : "carlosmartinez@outlook.com",
"pwd" : "33333333"
}, {
"_id" : ObjectId("5813bc184b57665d404678bf"),
"name" : "Sandra Molina",
"email" : "sandramolina@yahoo.com",
"pwd" : "44444444"
}];
usersList.forEach(function (user) {
db.users.insert(user);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment