337
Comment:
|
1405
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
== Login == * $ mongo 10.32.2.4 --authenticationDatabase admin --username test --password mypass * > db test * > show dbs * > use 9spokes * > db.getCollection("") * > show collections * db.getCollection("config_data").find() |
|
Line 13: | Line 23: |
=== Recover password === * stop the mongod service * edit /etc/mongod.conf {{{ :PRIMARY> use admin :PRIMARY> db.createUser({user:"root",pwd:"mongopwd",roles:[{role:"root",db:"admin"}]}); :PRIMARY> db.changeUserPassword("root","mongopwd") }}} |
|
Line 14: | Line 32: |
{{{ mongo admin --host 192.168.70.13 -u root -p mongopassword --eval 'rs.initiate({_id: "local_sandbox-MongoDB", members: [{_id: 0, host: "192.168.70.11:27017"},{_id: 1, host: "192.168.70.12:27017"},{_id: 2, host: "192.168.70.13:27017"}]})' }}} === Slow / Long running queries == * * $ mongo 10.32.2.4 --authenticationDatabase admin --username test --password mypass * > db.currentOp() * > db.currentOp({"secs_running": {$gte: 3}}) * Count documents in <db> <collection> * use <db>; * db.<collection>.count() -- |
MongoDB nosql notes
Login
- $ mongo 10.32.2.4 --authenticationDatabase admin --username test --password mypass
> db
- test
> show dbs
> use 9spokes
> db.getCollection("")
> show collections
- db.getCollection("config_data").find()
Replicaset
- View members
mongo admin --host $ip -u root -p $pass -eval "rs.status()"
- Check if current server is the write
mongo admin --host $ip -u root -p $pass --quiet --eval "db.isMaster()['ismaster']"
Recover password
- stop the mongod service
- edit /etc/mongod.conf
:PRIMARY> use admin :PRIMARY> db.createUser({user:"root",pwd:"mongopwd",roles:[{role:"root",db:"admin"}]}); :PRIMARY> db.changeUserPassword("root","mongopwd")
mongo admin --host 192.168.70.13 -u root -p mongopassword --eval 'rs.initiate({_id: "local_sandbox-MongoDB", members: [{_id: 0, host: "192.168.70.11:27017"},{_id: 1, host: "192.168.70.12:27017"},{_id: 2, host: "192.168.70.13:27017"}]})'
- * $ mongo 10.32.2.4 --authenticationDatabase admin --username test --password mypass
> db.currentOp()
> db.currentOp({"secs_running": {$gte: 3}})
Count documents in <db> <collection>
use <db>;
db.<collection>.count()
-- ...