Package com.mongodb.client
Interface MongoCursor<TResult>
-
- Type Parameters:
TResult- The type of documents the cursor contains
- All Superinterfaces:
AutoCloseable,Closeable,Iterator<TResult>
@NotThreadSafe public interface MongoCursor<TResult> extends Iterator<TResult>, Closeable
The Mongo Cursor interface implementing the iterator protocol.An application should ensure that a cursor is closed in all circumstances, e.g. using a try-with-resources statement:
try (MongoCursor<Document> cursor = collection.find().iterator()) { while (cursor.hasNext()) { System.out.println(cursor.next()); } }- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()com.mongodb.ServerAddressgetServerAddress()Returns the server addresscom.mongodb.ServerCursorgetServerCursor()Returns the server cursor, which can be null if the no cursor was created or if the cursor has been exhausted or killed.booleanhasNext()TResultnext()TResulttryNext()A specialnext()case that returns the next element in the iteration if available or null.-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
close
void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
tryNext
@Nullable TResult tryNext()
A specialnext()case that returns the next element in the iteration if available or null.Tailable cursors are an example where this is useful. A call to
tryNext()may return null, but in the future callingtryNext()would return a new element if a document had been added to the capped collection.- Returns:
- the next element in the iteration if available or null.
- MongoDB documentation
- Tailable Cursor
-
getServerCursor
@Nullable com.mongodb.ServerCursor getServerCursor()
Returns the server cursor, which can be null if the no cursor was created or if the cursor has been exhausted or killed.- Returns:
- the ServerCursor, which can be null.
-
getServerAddress
com.mongodb.ServerAddress getServerAddress()
Returns the server address- Returns:
- ServerAddress
-
-