简体   繁体   中英

List recent operations on mongodb

I'm using MongoDB with Node.js framework.

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. When I try to search by that _id in db - no document is found.

I tried to manually insert new document to db and it was successfull.

Is there a way I can trace these operations from db's point of view? 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 is a capped collection that can be searched as any other collection. Profiling can be noisy, and eventually you should have to change the size of the system.profile collection

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.

As noted by @Neil this has unfortunately become deprecated as of 2.6.

The only way currently is to write out ALL operations MongoDB performs, via @Rauls answer, and then use a query like:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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