Mongodb

From Halfface
Jump to navigation Jump to search

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

mongodump --ssl --host "database/mongo.inter.net" -u username -p P@ssw0rd --authenticationDatabase admin --db "database" --out=/tmp/database_2020-10-20"

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();'

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()