how to show query while using query annotations with MongoRepository with spring data(如何在使用带有 Spring 数据的 MongoRepository 的查询注释时显示查询)
问题描述
我在 Spring Boot 中使用 MongoRepository 来访问 mongo:
I'm using MongoRepository in spring boot to access mongo:
public interface MongoReadRepository extends MongoRepository<User, String> {
@Query(value = "{$where: 'this.name == ?0'}", count = true)
public Long countName(String name);
}
它可以工作,但我想知道它访问 mongo 的确切查询
and it could work, but i wonder know the exactly query it accessing mongo
怎么做?
我尝试在如下属性中添加一些配置:
i try to adding some config at properties like below:
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] 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
这篇关于如何在使用带有 Spring 数据的 MongoRepository 的查询注释时显示查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在使用带有 Spring 数据的 MongoRepository 的查询注释时显示查询
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01