com.mongodb.client.AggregateIterable.iterator (and similar API program elements, see https://github.com/mongodb/mongo-java-driver/pull/1677 to observe all of them) implicitly finds all documents if the pipeline ends with the $out/$merge stage. This is neither how users may expect the method to behave based on its normal behavior, nor is this helpful: in the rare situations when this is needed, a user may trivially execute the find himself, but in situations when this is not needed, it may cause an unexpected performance issue:
Tests run fine and it’s only on the production system that you just see abnormal network and CPU traffic.
Our production servers collapsed last year because of that. We deploy a change to use the aggregation framework to recompute some denormalisations (instead of a manual client side aggregation) We failed to find the cause of the problem and reverted that. And the same story happened very recently in a different context (link), fortunately not on prod.
- is related to
-
JAVA-5833 Weird behaviour with the `$merge` stage of an aggregation
-
- Closed
-