-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
com.mongodb.client.MongoIterable extends java.lang.Iterable. The MongoIterable.iterator methods returns MongoCursor, which is Closeable. Since users don't expect iterators returned by Iterable.iterator to require being closed, the method MongoCursor.cursor was added, which is equivalent to MongoIterable.iterator. But this, of course, does not solve the problem, because the MongoIterable.iterator is still there and is usable both explicitly and implicitly by the enhanced for statement, a.k.a. the for-each loop.
Some of our implementations of MongoCursor/BatchCursor (maybe all, I am not sure) auto-close themselves once exhausted, but this does not mean that applications do not have to close them. And there is a non-negligible chance that applications do not close cursors, especially if they are used in enhanced for statements.