如何在使用带有 Spring 数据的 MongoRepository 的查询注释时显示查询 [英] how to show query while using query annotations with MongoRepository with spring data

查看:18
本文介绍了如何在使用带有 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 的查询注释时显示查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆