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 的查询注释时显示查询
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
