11

Is there a way to find the query that was run against the database in spring data mongodb?

I know this is possible in case of JPA. So was just wondering if there was something similar in Spring data MongoDB?

2

2 Answers 2

10

The easiest way is to set the log level to DEBUG for org.springframework.data.mongodb.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried executing repository.findAll(predicate, sort) but the log only shows the filters but not the sort. Is there anyway I can see the sort query?
@user1955934 Yeah, also found this, in MongoTemplate class only find queries do not log sort part for unknown reasons
6
logging:
  level:
    org.springframework.data.mongodb.core.MongoTemplate: DEBUG

To clarify Oliver's answer add that to the application.yml file or properties file.

1 Comment

Thanks! logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG worked for me in application.properties

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.