# 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