Count in Spring Data MongoDB repository

后端 未结 3 973
说谎
说谎 2020-12-30 01:35

I wonder if there\'s any mechanism to use count in Spring Data MongoDB repository with @Query annotation? I would love to receive the number of doc

3条回答
  •  执笔经年
    2020-12-30 01:43

    Another way to do this using MongoRepository query templates:

    public interface MyRepository extends MongoRepository {
        Long countByLastname(String lastname);
    }
    

    See http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#repositories.query-methods.details

提交回复
热议问题