简体   繁体   English

列出mongodb上的最新操作

[英]List recent operations on mongodb

I'm using MongoDB with Node.js framework. 我正在将MongoDB与Node.js框架一起使用。

There is a weird behavior that some documents are not getting inserted into db, though from orm's point of view there are no errors: err = null in callback of Collection.create() and fresh document with _id is returned. 虽然从orm的角度来看没有错误,但是有些文档没有插入到db中,这是一种奇怪的行为: err = nullCollection.create()回调中,并返回带有_id新文档。 When I try to search by that _id in db - no document is found. 当我尝试通过db中的_id搜索时-未找到文档。

I tried to manually insert new document to db and it was successfull. 我试图手动将新文档插入db,但操作成功。

Is there a way I can trace these operations from db's point of view? 有没有一种方法可以从db的角度跟踪这些操作? Some command to list recent requests and their results..? 一些命令列出最近的请求及其结果。

You can enable profiling for all operations: 您可以为所有操作启用分析:

db.setProfilingLevel(2)

Then, look at system.profile collection to see what's happen. 然后,查看system.profile集合以查看发生了什么。 system.profile is a capped collection that can be searched as any other collection. system.profile是一个有上限的集合,可以像其他任何集合一样进行搜索。 Profiling can be noisy, and eventually you should have to change the size of the system.profile collection 分析可能会很嘈杂,最终您必须更改system.profile集合的大小

db.setProfilingLevel(0)

db.system.profile.drop()

db.createCollection( "system.profile", { capped: true, size:4000000 } )

db.setProfilingLevel(2)

The most notable way of tracking errors within MongoDB is to use the --diaglog option: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--diaglog with maybe a level of 3 , however 1 might be enough for you. 在MongoDB中跟踪错误的最值得注意的方法是使用--diaglog选项: http : --diaglog的级别可能为3 ,但是为1对您来说可能就足够了。

As noted by @Neil this has unfortunately become deprecated as of 2.6. 正如@Neil所指出的那样,不幸的是从2.6开始不推荐使用。

The only way currently is to write out ALL operations MongoDB performs, via @Rauls answer, and then use a query like: 当前唯一的方法是通过@Rauls答案写出MongoDB执行的所有操作,然后使用类似以下的查询:

db.system.profile.find({op:{$in:['update', 'insert', 'remove']}});

and possibly resize the capped collection used for profiling: http://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/#profiler-overhead to capture the amount you want. 并可能调整用于分析的上限集合的大小: http//docs.mongodb.org/manual/tutorial/manage-the-database-profiler/#profiler-overhead以捕获所需的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM