Mongo DB IMP commands




General :

1. Switch DB

use <DB>  or db.getSiblingDB("<DB>")




Users : 

1.  Change user password : 

use  <db>
db.changeUserPassword(<username>,<password>)

2. Authenticate user : 

db.auth (" <username>","password">)

3.  Login info : 

db.runCommand({connectionStatus : 1})

4. DB and roles 

show users






Replica Sets : 

1. Check master node :

db.isMaster()

2. Remove replica member using rs.remove() or rs.reconfig(): 

rs.remove("<hostname>:port")

or

  •  Remove replica member using rs.reconfig() ... Check mongo docs for the same.
3. Oplog size and window 

rs.printReplicationInfo()

You must run replSetResizeOplog on each replica set member in your cluster to change the oplog size for all members.


Diagnostics and Troubleshooting : 

  • CurrentOp doesn not show inactive connections.
  • db.ServerStatus() output can be customized with db.runCommand , 
ex. db.runCommand({ serverStatus : 1 , repl : 0 , metrix : 0, locks : 1 , wiredTiger :0 })

  • Object.keys( ) function tells us keys of function.  i.e. Object.keys(db.serverStatus())
  • db.serverStatus().host , db.serverStatus().version ,db.serverStatus().uptime, db.serverStatus().localTime , db.serverStatus().connections  <-- This value depends on Unix ulimit value and max connection configuration for mongod.
  • db.serverStatus().asserts  --> Asserts is a document that reports the number of assertion errors raised since the server process started.
  • db.serverStatus().opcounters --> Gives information about no. of insert/update / delete operations irrespective of documents affected.
  • db.serverStatus().metrics.documents -->  keeps tracks of actual documents affected.
  • db.serverStatus().opcountersRepl --> Same as above but as result of replication process.
  • db.serverStatus().opLatencies --> read/write/command latencies in MicroSeconds.
  • db.serverStatus().mem
  • db.getProfilingLevel() and set level 0 for production to remove overhead. we can find profile info at db.system.profile.find()
  • Other utilities 
mongoimport
mongoExport
mongodump
mongorestore
bsondump
mongooplog
mongostat  - Give stats about read/write response time on given namespace.
mongotop
mongoreplay - Network diagnostics and analysis tool. Monitor,Record and Replay.
mongoperf  - Performance testing tool. Test server's i/o performance.
mongoldap  - Use to Verify LDAP configuration
mtools -  Analyze, simulate and debug issue with Mongo deployment.


Comments

Popular posts from this blog