12

I'm using Spring Data's Querydsl integration to execute my queries using predicates.

findAll(predicate, pageable)

Is there a way to dump the actual raw queries/commands that get executed?

I have also looked at the answer to this question and it wasn't working for me.. Configure logging for the MongoDB Java driver

--Update-- I've managed to get the logging working by adding logging.level.org.mongodb.driver=DEBUG in application.properties (not log4j.properties)

But still, I can't see the raw query that's being performed:

2016-03-23 21:50:56 DEBUG query:56 - Query completed 2016-03-23 21:50:56 DEBUG query:56 - Sending query of namespace testdb.reservation on connection [connectionId{localValue:4, serverValue:42631}] to server ds046785.mongolab.com:39186

4
  • On the MongoDB side, you may use the profiler with a profiling level set to 2 to log all the queries and commands the instance receives.
    – Nicolas
    Commented Mar 13, 2016 at 10:43
  • Ultimately, mongo java driver is responsible for sending the queries, so you can still set the org.mongodb log level to DEBUG and see the issued queries Commented Mar 13, 2016 at 11:07
  • I've added this line in my log4j.properties: log4j.logger.org.mongodb.driver=DEBUG but there's still nothing logged Commented Mar 13, 2016 at 15:15
  • You might want to include your logging config in general and do some testing that it is configured correctly to at least log other components. Ultimately this does all have to go through the driver as was mentioned, so logging there would be the most valid option. I suggest you have configuration issues that you should include in the question so they can be resolved. Commented Mar 21, 2016 at 6:30

1 Answer 1

5
+25

Enable the profiler by setting the profile value using the following command in the mongo shell:

db.setProfilingLevel(2)

output of the profiler can be viewed using this command:

db.system.profile.find( { millis : { $gt : 100 } } )

This command displays all operations longer than 100 milliseconds

2
  • I've run the command db.setProfilingLevel(2) and then I run my query against the db, but the db.system.profile.find ({millis:{$gt:0}}) wont return the query im looking for Commented Mar 23, 2016 at 9:08
  • Yeah, same here, best will be to clean profile and run 'db.system.profile.find()' alone. You can clean profile like this: 'db.setProfilingLevel(0); db.system.profile.drop(); db.setProfilingLevel(2);'
    – megalucio
    Commented Feb 2, 2017 at 19:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.