Count in Spring Data MongoDB repository

paul :

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 documents that I have without having to get all of them.

Basically, the equivalent of this in Java:

db.test.find({"type":"foo"}).count 
wmax :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

StackOverflowError when calling Spring Data MongoDB repository method with a page size bigger than 36

Spring data mongodb repository findAll field exclusion

Repository query with a List parameter in Spring Data MongoDB

How to query with greaterThan for an embedded document using Spring Data MongoDB Repository?

How to count array elements properly with multiple aggregation in Spring Data MongoDB?

Spring Data Repository autowiring fails

Spring Data MongoDB tries to generate queries for custom repository methods

Cannot find the Repository bean in Spring boot / Spring Data MongoDB

Spring Data - Repository bean ID

Spring Data Repository - Method Signatures

Custom MongoDB spring data repository

How to use projecting types in Spring Data MongoDB repository's query methods?

Spring Data Mongodb - repository for collection with different types

Spring Data MongoDB repository method delete by list of id

Get last created document in Mongodb using Spring Data repository

Can Spring Data MongoDB be configured to support a different database for each repository?

Spring Data: Enumeration and Repository issue

Spring Data MongoDB Repository - JPA Specifications like

Extend Spring Data Repository

Rest API with Spring Data MongoDB - Repository method not working

Truncate and count positions in Spring with Mongodb

Using a custom ID in a Spring Data REST repository backed by MongoDB

spring data mongo repository is null

MongoDB:Spring data:- Embedded Array Count

Spring Data Repository StackOverflow

spring data inheritance for repository reuse

Java repository - Spring Data JPA

spring data repository Implenation

Spring data repository with empty IN clause

TOP Ranking

  1. 1

    pump.io port in URL

  2. 2

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  5. 5

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  6. 6

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  7. 7

    mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection refused)

  8. 8

    What's the point of declaring a const in JavaScript

  9. 9

    The prefix "andriod" for attribute "andriod:name" associated with an element type "application" is not bound?

  10. 10

    Change both state and params dynamically in ui-sref

  11. 11

    Copying a slide from one Google Slides presentation into another

  12. 12

    Grails with Oracle thick OCI driver authenticate to Oracle with wrong user

  13. 13

    Converting a class method to a property with a backing field

  14. 14

    How to use Angular2 and Typescript in Jsfiddle

  15. 15

    clojure.lang.LazySeq cannot be cast to class clojure.lang.Associative

  16. 16

    Inner Loop design for webscrapping

  17. 17

    How to set tab order for array of cluster,where cluster elements have different data types in LabVIEW?

  18. 18

    Removed zsh, but forgot to change shell back to bash, and now Ubuntu crashes (wsl)

  19. 19

    IServiceCollection does not contain a defintion for AddHttpClient

  20. 20

    What's the difference between conflict and compulsory cache miss?

  21. 21

    How to run blender on webserver?

HotTag

Archive