spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.59k stars 1.07k forks source link

MongoTemplate.count Specify strategy #4727

Closed dv2018f closed 1 week ago

dv2018f commented 3 weeks ago

Upon reviewing the source code, it was found that MongoTemplate executes the count method. The underlying default is AGGREGATE. Can we specify it as the COMMAND policy, as aggregate takes longer to scan public long countDocuments(Bson filter, CountOptions options) { return this.executeCount((ClientSession)null, filter, options, CountStrategy.AGGREGATE); }

christophstrobl commented 3 weeks ago

I'm not entirely sure I understand what you want to achieve given MongoOperations has dedicated methods like estimatedCount to operate upon collection statistics. Additionally you could call MongoTemplate#useEstimatedCount(...) to apply a different count strategy.

Further more the snippet from the description refers to the MongoDB client API of MongoCollectionImpl which is maintained by the java drivers team at MongoDB. Please report issues/enhancements with them here.

spring-projects-issues commented 2 weeks ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 1 week ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.