Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[edison-mongo] AbstractMongoRepository.size() is unsuitable for big collections #121

Open
simonwiesmann8732 opened this issue May 18, 2020 · 1 comment

Comments

@simonwiesmann8732
Copy link

Hello edisoneers,

AbstractMongoRepository.size() uses the MongoDB collection's countDocuments() internally. This method is unsuitable for timely responses on big collections as it

wraps the $group aggregation stage with a $sum expression to perform the count and is available for use in Transactions.

For us the operation was timing out with a timeout of 30 seconds (30.000 millis) on a collection with more than 30m documents. The original behavior of edison-mongo changed with this commit when a switch was made from the deprecated count() (which was not transaction-safe).

The direct counterpart to the deprecated count() is estimatedDocumentCount().

The danger in using size() as it is is that everything is fine when you create a new collection and only have a few documents and will fail as the collections grows without having made any changes to the code. Thus, it would make sense to support both methods and make the difference obvious (maybe estimatedSize() and atomicSize() ?).

@ghost
Copy link

ghost commented May 28, 2020

Hi Simon,

thank you for your feedback! We'll have a look into this, your suggestion sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant