MongoDB logging all queries

João Rocha da Silva picture João Rocha da Silva · Mar 4, 2013 · Viewed 174.6k times · Source

The question is as basic as it is simple... How do you log all queries in a "tail"able log file in mongodb?

I have tried:

  • setting the profiling level
  • setting the slow ms parameter starting
  • mongod with the -vv option

The /var/log/mongodb/mongodb.log keeps showing just the current number of active connections...

Answer

Kristóf Dombi picture Kristóf Dombi · Feb 12, 2014

You can log all queries:

$ mongo
MongoDB shell version: 2.4.9
connecting to: test
> use myDb
switched to db myDb
> db.getProfilingLevel()
0
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 1, "ok" : 1 }
> db.getProfilingLevel()
2
> db.system.profile.find().pretty()

Source: http://docs.mongodb.org/manual/reference/method/db.setProfilingLevel/

db.setProfilingLevel(2) means "log all operations".