我如何查看mongodb正在执行的查询? [英] How do i view queries being executed by my mongodb?
问题描述
我一直在log/development.log中看到此消息,我想知道该查询是否实际上在我的数据库中执行:
I keep on seeing this in my log/development.log, and I am wondering whether this query is actually being executed in my database:
MONGODB (0ms) socialcrunch_development['tags'].find({:_id=>"secrets"}).limit(-1).sort([[:_id, :asc]])
我可以看到在mongo db上执行的查询,因此我可以对它们进行计数,它们通常都是.find命令,还是应该寻找其他内容?
Ho can I see the queries being executed on my mongo db, so I can count them, should they all typically be .find commands, or should i being looking for something else?
推荐答案
打印所有活动读物:
db.currentOp().inprog.forEach(
function(d){
if(d.waitingForLock && d.lockType != "read")
printjson(d)
})
打印所有活动写入:
db.currentOp().inprog.forEach(
function(d){
if(d.waitingForLock && d.lockType != "write")
printjson(d)
})
如果愿意,可以使用currentOp.op
按特定的操作类型(插入,更新,删除等)进行过滤,从而获得更多的粒度.
You can get a lot more granular if you like by using currentOp.op
to filter by a specific operation type (insert, update, delete, etc).
从MongoDB.org的文档中查看以下页面,以获取更多信息: http://docs.mongodb.org/manual/reference/current-op/
Check out the following page from MongoDB.org's documentation for more info: http://docs.mongodb.org/manual/reference/current-op/
这篇关于我如何查看mongodb正在执行的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!