[英]How can I verify every query log from express.js server to mongo db?
I looked manage-the-database-profiler I had set profile level as db.setProfilingLevel(2,200)
. 我查看了已将配置文件级别设置为
db.setProfilingLevel(2,200)
manage-the-database-profiler 。 At my page is calling following mongo DB using mongoose like following 在我的页面上使用mongoose调用以下mongo DB,如下所示
mycollection.findOne({MyId: 1}, function(err, data){
})
When I look log file, there's no access to "mycollection". 当我查看日志文件时,无法访问“ mycollection”。 Also, the log file sometime do contains query on some of my page like following.
另外,日志文件有时确实包含对我的某些页面的查询,如下所示。
2014-07-30T13:11:59.258-0700 [conn33] query myDB.myOtherCollection query: { MyID: 100 } planSummary: COLLSCAN ntoskip:0 nscanned:850 nscannedObjects:850 keyUpdates:0 numYields:7 locks(micros) r:6101 nreturned:0 reslen:20 3ms 2014-07-30T13:11:59.258-0700 [conn33]查询myDB.myOtherCollection查询:{MyID:100} planSummary:COLLSCAN ntoskip:0 nscanned:850 nscannedObjects:850 keyUpdates:0 numYields:7 locks(micros)r:6101 nreturned:0 reslen:20 3ms
So what is a way to show all query log to mongo database? 那么,如何将所有查询日志显示到mongo数据库呢?
由于您使用的是猫鼬,因此可以通过启用调试来查看执行的查询。
mongoose.set('debug', true)
db.setProfilingLevel
has an optional level
argument that, when set to 2, records all operations in the system.profile
collection of the database, not in the log file. db.setProfilingLevel
有一个可选的level
参数,当设置为2时,它将所有操作记录在数据库的system.profile
集合中, 而不是记录在日志文件中。 The slowMS
argument determines how slow a query must be before it is logged to the log file. slowMS
参数确定查询在记录到日志文件之前必须达到的速度。
If you want to closely monitor activity in your collections, consider using MMS for monitoring as it exposes a lot of useful usage, performance, and profiling information in a more friendly format than system.profile
. 如果要密切监视集合中的活动,请考虑使用MMS进行监视,因为它以比
system.profile
更友好的格式公开了许多有用的用法,性能和配置文件信息。
如果将第二个参数slowMS设置为1ms,这将记录所有耗时超过1ms的查询-这几乎是所有查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.