Logging MongoDB Queries in Java?

In this post, we will learn to enable logging MongoDB queries in Java. For this example, we need a MongoDB driver for Java.

To display the query in the log we need to set the org.mongodb.driver level to debug.

  • If you are using Spring Boot project and want to log MongoDB query then you can use the following in your application.properties file:
logging.level.org.mongodb.driver=debug
  • If you are using a standalone Java application and using Logback for logging then you can use the following in your logback.xml file:
<logger name="org.mongodb.driver" level="debug"></logger>


Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments