如何使用MongoRepository与spring数据一起使用查询注释时显示查询
我在spring boot中使用MongoRepository来访问mongo:
public interface MongoReadRepository extends MongoRepository { @Query(value = "{$where: 'this.name == ?0'}", count = true) public Long countName(String name); }
它可以工作,但我想知道它访问mongo的确切查询
怎么做?
我尝试在以下属性中添加一些配置:
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG logging.level.org.springframework.data.mongodb.repository.Query=DEBUG
并且不工作。
有人可以帮忙吗?
我在application.properties中添加行(下面)并且工作正常:
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
查询:
@Query("{$and: [{'$or' : [{ 'name': {$regex : ?0, $options: 'i'}}, {'description': {$regex : ?1, $options: 'i'}}]}, { 'deleted' : ?2 }]}")
获取此日志:
2016-09-27 10:53:26.245 DEBUG 13604 --- [nio-9090-exec-3] osdata.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
您也可以使用yml配置文件,将其放在application.yml文件中。
logging: level: org.springframework.data.mongodb.core.MongoTemplate: DEBUG
对于ReactiveMongo,将此属性添加到.properties文件中
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG