-
Notifications
You must be signed in to change notification settings - Fork 1.1k
count() $maxTimeMS not work #4374
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
Comments
Add maxTimeMS to AggregationOptions [DATAMONGO-2390] #3249 Based on this PR, it seems that aggregation is needed to solve this problem |
@zhaohuiio thank you for the additional explanation. I see, |
I found a solution( Base on spring-data-mongodb version: 4.0.5 )
But In earlier versions, this method did not work because Aggregation.newAggregationOptions().maxTime() did not be provided |
One last question, What I don't understand here is why the count method of the high version of spring-data-mongodb should be implemented by aggregation at the bottom !
Execute code, generated log
After many times of verification, the efficiency of the old version of mongodb is higher than that of the new version using aggregation to calculate values.
2.04s
2.63s Looking forward to your reply ! |
Count can operate upon collection statistics which is fast but may return an inaccurate result. Details can be found in the MongoDB documentation. |
mongodb version 3.6.23
jdk 11
system: MacOS 12.4
Criteria criteria = Criteria.where("token").is("true");
Query query = new Query(criteria).maxTimeMsec(1000);;
long count = mongoTemplate.count(query, DBObject.class, "public_leads");
The desired effect is that after 1 second of execution, if it doesn't compute, then immediately break it. But this will not happen, and count() will complete the entire evaluation without being interrupted by a query timeout
db.collection.count({query}, {maxTimeMS: 1000})
Native mongodb js queries work, but not in the framework, I tried the two versions respectively, spring-data-mongodb version: 3.4.11 , 4.0.5 will be repeated
Criteria criteria = Criteria.where("token").is("true");
Query query = new Query(criteria).maxTimeMsec(1000);
List list = mongoTemplate.find(query, DBObject.class, "public_leads");
There's no problem with using it that way
The text was updated successfully, but these errors were encountered: