how to show query while using query annotations with MongoRepository with spring data

前端 未结 4 973
無奈伤痛
無奈伤痛 2020-12-14 05:43

I\'m using MongoRepository in spring boot to access mongo:

public interface MongoReadRepository extends MongoRepository {
    @Query(valu         


        
相关标签:
4条回答
  • 2020-12-14 06:25

    Also, you can use a yml config file, put it in your application.yml file.

    logging:
      level:
        org.springframework.data.mongodb.core.MongoTemplate: DEBUG
    
    0 讨论(0)
  • 2020-12-14 06:33

    I add the line (below) in application.properties and works fine:

    logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
    

    for query:

    @Query("{$and: [{'$or' : [{ 'name': {$regex : ?0, $options: 'i'}}, {'description': {$regex : ?1, $options: 'i'}}]}, { 'deleted' : ?2 }]}")
    

    obtain this log:

    2016-09-27 10:53:26.245 DEBUG 13604 --- [nio-9090-exec-3] o.s.data.mongodb.core.MongoTemplate      : find using query: { "$and" : [ { "$or" : [ { "name" : { "$regex" : "c" , "$options" : "i"}} , { "description" : { "$regex" : "c" , "$options" : "i"}}]} , { "deleted" : false}]} fields: null for class: class com.habber.domain.Entity in collection: entities
    
    0 讨论(0)
  • 2020-12-14 06:41

    This is a late answer but I found the correct answer hasn't been given yet based on the question.

    The answer already given by the people may be valid for other scenarios. But, if you are using the MongoRepository then the correct configuration would be the following:

    logging.level.org.springframework.data.mongodb.repository.query= debug
    

    You are using the Query in your configuration instead of query which is wrong.

    When you add correct configuration then the logger would be like:

    25-06-2020 17:58:43.301 [http-nio-9001-exec-10] DEBUG o.s.d.m.r.query.MongoQueryCreator.complete(162) - Created query Query: { "customer.id" : 2}, Fields: {}, Sort: {}
    
    0 讨论(0)
  • 2020-12-14 06:45

    For ReactiveMongo add this property to your .properties file

    logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG
    
    0 讨论(0)
提交回复
热议问题