TResult
- The type of documents the cursor contains@NotThreadSafe public interface MongoCursor<TResult> extends java.util.Iterator<TResult>, java.io.Closeable
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()); } }
Modifier and Type | Method and Description |
---|---|
void |
close() |
ServerAddress |
getServerAddress()
Returns the server address
|
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.
|
boolean |
hasNext() |
TResult |
next() |
TResult |
tryNext()
A special
next() case that returns the next element in the iteration if available or null. |
void close()
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
boolean hasNext()
hasNext
in interface java.util.Iterator<TResult>
@Nullable TResult tryNext()
next()
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 calling
tryNext()
would return a new element if a document had been added to the capped collection.
@Nullable ServerCursor getServerCursor()
ServerAddress getServerAddress()
Copyright © 2010 - 2020 Adobe. All Rights Reserved