Count in Spring Data MongoDB repository

后端 未结 3 1002
说谎
说谎 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:41

    For me this solutions works like a charm( using spring-data-mongodb 1.3.1.RELEASE ), I just had the same problem atm and solved it like this(just a short snippet from my code at work):

    @Query(value = "{'productDetails.productType': {$regex: ?0, $options: 'i'}, 'sourceDescriptor': ?1}", count = true)
    public Long countFetchedDocumentsForCategory(String cat, String sourceDescriptor);
    

提交回复
热议问题