1) Command to reindex all mongodb collections
2) Finding and Terminating Long-Running Operations in MongoDB
3) Repairing a Collection’s Datafiles
Command to reindex all mongodb collections
4) Repairing a Collection’s Indexes
5) Repairing a Server
6) Shutting Down a Server
7) Enabling and Disabling the DB Profiler
8) mongoDB health check commands
=========================================================
1) Command to reindex all mongodb collections
db.getCollectionNames().forEach(function(coll_name) {
var coll = db.getCollection(coll_name);
coll.reIndex();
});
db.getCollectionNames().forEach(function(collection){db[collection].reIndex()});
=========================================================
2)Finding and Terminating Long-Running Operations in MongoDB
db.currentOp().inprog.forEach(
function(op) {
if(op.secs_running > 5) printjson(op);
}
)
kill command:- db.killOp(op_id)
=========================================================
3) Repairing a Collection’s Datafiles
db.repairDatabase()
=========================================================
4) Repairing a Collection’s Indexes
db.posts.reIndex()
=========================================================
5) Repairing a Server
mongod --dbpath /data/db --repair
6) Shutting Down a Server
$mongo
>use admin
>db.shutdownServer()
=========================================================
7) Enabling and Disabling the DB Profiler
$mongo
>use blog
>db.setProfilingLevel(1)
It is an equally simple matter to disable the profiler:
$mongo
>use blog
>db.setProfilingLevel(0)
maximum query execution time value in milliseconds (ms).
>db.setProfilingLevel(1,500)
profiling for all queries by setting the profiler level to 2.
>db.setProfilingLevel(2)
=========================================================
8) mongoDB health check commands
a) mongostat, b) mongotop, c) db.serverStatus(), d) db.stats(), e) db.collection.stats(),
f) db.printReplicationInfo(), g) rs.status(), h) sh.status()