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

Community
  • 1
  • 1
user1955934
  • 3,185
  • 5
  • 42
  • 68
  • On the MongoDB side, you may use the [profiler](https://docs.mongodb.org/manual/administration/analyzing-mongodb-performance/#database-profiling) with a profiling level set to `2` to log all the queries and commands the instance receives. – Nicolas Mar 13 '16 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 – Ali Dehghani Mar 13 '16 at 11:07
  • I've added this line in my log4j.properties: log4j.logger.org.mongodb.driver=DEBUG but there's still nothing logged – user1955934 Mar 13 '16 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. – Blakes Seven Mar 21 '16 at 06:30

1 Answers1

5

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

megalucio
  • 5,051
  • 2
  • 22
  • 26
BDRSuite
  • 1,594
  • 1
  • 10
  • 15
  • 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 – user1955934 Mar 23 '16 at 09: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 Feb 02 '17 at 19:34