Skip to content

MongoCollection#countDocuments Performance in Driver 4.x [DATAMONGO-2669] #3522

Closed
@spring-projects-issues

Description

@spring-projects-issues

Richard Kwasnicki opened DATAMONGO-2669 and commented

When using SimpleMongoRepository.count(), MongoDB is now performing a collscan instead of using estimated count by metadata. I had a short discussion with a MongoDB developer at https://developer.mongodb.com/community/forums/t/upgrading-java-mongodriver-3-x-to-4-x-leads-to-lock-with-aggregate-countstrategy/12754

He advised to never use a non-empty query on exact count and better go with MongoCollection#estimatedDocumentCount instead of  MongoCollection#countDocuments

For us it took minutes to perform a count query on a quite large collection on startup


Affects: 3.1.1 (2020.0.1)

Metadata

Metadata

Labels

in: coreIssues in core supporttype: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions