Package com.mongodb.client
Interface MongoIterable<TResult>
- Type Parameters:
TResult- The type that this iterable will decode documents to.
- All Superinterfaces:
Iterable<TResult>
- All Known Subinterfaces:
AggregateIterable<TResult>,ChangeStreamIterable<TResult>,DistinctIterable<TResult>,FindIterable<TResult>,GridFSFindIterable,ListCollectionNamesIterable,ListCollectionsIterable<TResult>,ListDatabasesIterable<TResult>,ListIndexesIterable<TResult>,ListSearchIndexesIterable<TResult>,MapReduceIterable<TResult>
The MongoIterable is the results from an operation, such as a query.
- Since:
- 3.0
-
Method Summary
Modifier and TypeMethodDescriptionbatchSize(int batchSize) Sets the number of documents to return per batch.cursor()Returns a cursor used for iterating over elements of typeTResult.first()Helper to return the first item in the iterator or null.<A extends Collection<? super TResult>>
Ainto(A target) Iterates over all the documents, adding each to the given target.iterator()<U> MongoIterable<U>Maps this iterable from the source document type to the target document type.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
iterator
MongoCursor<TResult> iterator()- Specified by:
iteratorin interfaceIterable<TResult>- Returns:
- A
MongoCursorthat must be closed.
-
cursor
MongoCursor<TResult> cursor()Returns a cursor used for iterating over elements of typeTResult. The cursor is primarily used for change streams.- Returns:
- a cursor equivalent to that returned from
iterator(). - Since:
- 3.11
-
first
Helper to return the first item in the iterator or null.- Returns:
- T the first item or null.
-
map
Maps this iterable from the source document type to the target document type.- Type Parameters:
U- the target document type- Parameters:
mapper- a function that maps from the source to the target document type- Returns:
- an iterable which maps T to U
-
into
Iterates over all the documents, adding each to the given target.- Type Parameters:
A- the collection type- Parameters:
target- the collection to insert into- Returns:
- the target
-
batchSize
Sets the number of documents to return per batch.- Parameters:
batchSize- the batch size- Returns:
- this
- MongoDB documentation
- Batch Size
-