Mongodb: Difference between revisions
Jump to navigation
Jump to search
(9 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
=list databases= | =list databases= | ||
show dbs | show dbs | ||
Via script | |||
rs.slaveOk();db.adminCommand('listDatabases') | |||
=mongodump= | |||
Dump database | |||
mongodump --ssl --host "database/mongo.inter.net" -u username -p P@ssw0rd --authenticationDatabase admin --db "database" --out=/tmp/database_2020-10-20" | |||
=restore database= | |||
mongo -ssl --host database/mongo.inter.net -u username -p P@ssw0rd --authenticationDatabase admin | |||
db.copyDatabase("dbname", "dbname-oldprod-date");> use dbname; | |||
db.dropDatabase(); | |||
mongorestore --ssl --host database/mongo.inter.net -u username -p P@ssw0rd --authenticationDatabase admin --gzip --db dbname /<path>/dbname | |||
=Login as ldap user= | |||
mongo --ssl --sslCAFile /etc/ssl/mongodb-ca.crt -u username --host mongodb.inter.net --port 27017 --authenticationDatabase '$external' --authenticationMechanism 'PLAIN' -pP@ssW0rd --eval 'rs.status();' | |||
mongo --ssl -u $username --host $(hostname -f) --port 27017 --authenticationDatabase '$external' --authenticationMechanism 'PLAIN' -p $PASSWORD | |||
=Look at database status= | |||
mongo --ssl --host mongodb.inter.net --quiet -u username -p P@ssW0rd --authenticationDatabase admin --eval 'rs.status();' | head | |||
=Put db i state 2= | |||
rs.stepDown(120); | |||
=Look at connections= | |||
'db.currentOp()' | |||
=List databases.= | |||
'db.getMongo().getDBNames();' | |||
=List users= | |||
echo -e 'use $external \n db.getUsers();' | mongo --ssl --host mongodb.inter.net --quiet -u username -p P@ssW0rd --authenticationDatabase admin --eval 'rs.status();' | |||
=Create user= | |||
mongo << END | |||
/// setup authentication | |||
use admin; | |||
db.addUser({"pwd" : "yO9HUQiuLIMfzHK6sBJF0DdwZKiwAq9X", "roles" : [ "userAdminAnyDatabase", "readWrite" ], "user" : "admin" }); | |||
use mathem | |||
//db.addUser("mathem", "Q0Nay1xeY9zq"); | |||
db.addUser({"pwd" : "Q0Nay1xeY9zq", "roles" : [ "userAdminAnyDatabase", "readWrite" ], "user" : "admin" }) | |||
END | |||
=Which version= | |||
db.version() | |||
=show process list= | |||
Show all operations | |||
db.currentOp( { "$all": true } ) |
Latest revision as of 10:50, 3 May 2024
connect
mongo
run command(list cluster information)
mongo --ssl --host mongo.inter.net --quiet -u admin -p P@ssW0rd --authenticationDatabase admin --eval 'rs.status();'
list databases
show dbs
Via script
rs.slaveOk();db.adminCommand('listDatabases')
mongodump
Dump database
mongodump --ssl --host "database/mongo.inter.net" -u username -p P@ssw0rd --authenticationDatabase admin --db "database" --out=/tmp/database_2020-10-20"
restore database
mongo -ssl --host database/mongo.inter.net -u username -p P@ssw0rd --authenticationDatabase admin db.copyDatabase("dbname", "dbname-oldprod-date");> use dbname; db.dropDatabase(); mongorestore --ssl --host database/mongo.inter.net -u username -p P@ssw0rd --authenticationDatabase admin --gzip --db dbname /<path>/dbname
Login as ldap user
mongo --ssl --sslCAFile /etc/ssl/mongodb-ca.crt -u username --host mongodb.inter.net --port 27017 --authenticationDatabase '$external' --authenticationMechanism 'PLAIN' -pP@ssW0rd --eval 'rs.status();' mongo --ssl -u $username --host $(hostname -f) --port 27017 --authenticationDatabase '$external' --authenticationMechanism 'PLAIN' -p $PASSWORD
Look at database status
mongo --ssl --host mongodb.inter.net --quiet -u username -p P@ssW0rd --authenticationDatabase admin --eval 'rs.status();' | head
Put db i state 2
rs.stepDown(120);
Look at connections
'db.currentOp()'
List databases.
'db.getMongo().getDBNames();'
List users
echo -e 'use $external \n db.getUsers();' | mongo --ssl --host mongodb.inter.net --quiet -u username -p P@ssW0rd --authenticationDatabase admin --eval 'rs.status();'
Create user
mongo << END /// setup authentication use admin; db.addUser({"pwd" : "yO9HUQiuLIMfzHK6sBJF0DdwZKiwAq9X", "roles" : [ "userAdminAnyDatabase", "readWrite" ], "user" : "admin" }); use mathem //db.addUser("mathem", "Q0Nay1xeY9zq"); db.addUser({"pwd" : "Q0Nay1xeY9zq", "roles" : [ "userAdminAnyDatabase", "readWrite" ], "user" : "admin" }) END
Which version
db.version()
show process list
Show all operations
db.currentOp( { "$all": true } )