= MongoDb/Performance = * [[attachment:MongoDB-Performance-Best-Practices.pdf]] https://neotan.github.io/images/media/MongoDB-Performance-Best-Practices.pdf == Indicate in connection string to not use primary server in cluster == * mongodb://user:pass@urls/db?readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS&readConcernLevel=local === 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 * use ; * db..count() * DB locks * > db.serverStatus().globalLock * > db.serverStatus().locks * DB version , want > 3.2 wiretiger document level locking * > db.version() * DB memory usage should be less than ram * > db.serverStatus().mem * > db.serverStatus().wiredTiger.cache * Check number of connections * db.serverStatus().connections * Check indexs on a collection * db..getIndexes() == From mongodb atlas help - how to view active connections == * view active connections in shell {{{ db.currentOp(true).inprog.forEach( function(op) { if(op.active = true && op.client != undefined) { var miniOp = { client : op.client, description : op.desc }; printjson(miniOp);} } ); }}} ---- CategoryPerformance