Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

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

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);
}

and it could work, but i wonder know the exactly query it accessing mongo

how to do that?

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

and don't work.

could somebody help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...