查看mongodb執行命令耗時


 

1.開啟日志,超過10毫秒的都記錄
db.setProfilingLevel( 1 , 10)

 

2.執行命令
db.metric.aggregate([{$group: {_id: '$month', totalcnt: {$sum: 1}}}])

 

3.查看執行情況

> db.system.profile.find().pretty() { "op" : "command", "ns" : "db_test.metric", "command" : { "aggregate" : "metric", "pipeline" : [ { "$group" : { "_id" : "$month", "totalcnt" : { "$sum" : 1 } } } ], "cursor" : { }, "lsid" : { "id" : UUID("fda589d9-c981-4f93-9341-fca9980f77b3") }, "$readPreference" : { "mode" : "secondaryPreferred" }, "$db" : "db_test" }, "keysExamined" : 0, "docsExamined" : 1000000, "cursorExhausted" : true, "numYield" : 1026, "nreturned" : 1, "locks" : { "ReplicationStateTransition" : { "acquireCount" : { "w" : NumberLong(1058) } }, "Global" : { "acquireCount" : { "r" : NumberLong(1058) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1057) } }, "Collection" : { "acquireCount" : { "r" : NumberLong(1057) } }, "Mutex" : { "acquireCount" : { "r" : NumberLong(31) } } }, "flowControl" : { }, "storage" : { }, "responseLength" : 149, "protocol" : "op_msg", "millis" : 1732, "planSummary" : "COLLSCAN", "ts" : ISODate("2022-03-24T03:29:11.433Z"), "client" : "192.168.1.135", "appName" : "MongoDB Shell", "allUsers" : [ ], "user" : "" }

 

這里執行1732毫秒

 

4.關閉日志
db.setProfilingLevel(0)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM