简体   繁体   English

如何验证从express.js服务器到mongo db的每个查询日志?

[英]How can I verify every query log from express.js server to mongo db?

How can I verify every query from express.js server to mongo db? 如何验证从express.js服务器到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.

相关问题 如何在Express.js上的路由器中对数据库使用少量查询 - How can I use few query to DB within router on Express.js 我可以在 express.js 中从“GET”重定向到“POST”查询吗? - Can I redirect from 'GET' to 'POST' query in express.js? 如何解决 express.js 中承诺的 mysql 查询? - How can I resolve a promised mysql query in express.js? 在Node.js / Express.js中,如何将JSON对象从服务器传输到客户端? - In Node.js/Express.js, how can I transfer a JSON object from server to client? 在Express.js服务器中,如何发送从HTTP请求获取的HTML(带有样式和js)作为响应? - In an Express.js server, how can I send an HTML (with style and js) acquired from a HTTP request, as a response? Electron:Express.js服务器在准备好之前查询Mongo DB - Electron: Express.js server queries Mongo DB before it's ready 如何使用node.js和express.js向Mongo DB Atlas发出发布请求 - How to make a post request to mongo db atlas using node.js and express.js 如何在Express.js中为每个路由存储变量? - How do I store a variable for every route in Express.js? 如何避免在Express.js的每个路由器上登录到SalesForce数据库? - How can I avoid logging into SalesForce databases on every router in Express.js? 如何将查询参数添加到 node.js/express.js res.redirect 函数? - How can I add query parameters to a node.js/express.js res.redirect function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM