Skip to content

SimpleMongoRepository.java's public Page<T> findAll(Pageable pageable) runs 1000 times slower than before #4761

@herbertwu

Description

@herbertwu

The findAll(Pageable pageable) method on a given collection calls count() first. The count() call uses MongoDB driver's collection.countDocuments(emptyQuery) to get the result.

However MongoDB driver collection.countDocuments(emptyQuery) changed the implementation lately and uses the much slower "aggregate" query than the original "count" query.
The "count" query is very fast. And MongoDB driver added a new method collection.estimatedDocumentCount() to use "count" query.

Can we enhance findAll(Pageable pageable) to add option to use the estimatedDocumentCount()?

In my application, findAll(Pageable pageable) method(finding oldest 100 records by timestamp) runs about ~1000 times slower after driver upgrade because of the count() using MongoDB driver's exact count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions