11/*
2- * Copyright 2011-2021 the original author or authors.
2+ * Copyright 2011-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import java .util .Set ;
2121import java .util .function .Consumer ;
2222import java .util .function .Supplier ;
23+ import java .util .stream .Stream ;
2324
2425import org .bson .Document ;
26+
2527import org .springframework .data .geo .GeoResults ;
2628import org .springframework .data .mongodb .core .BulkOperations .BulkMode ;
2729import org .springframework .data .mongodb .core .aggregation .Aggregation ;
4244import org .springframework .data .mongodb .core .query .Query ;
4345import org .springframework .data .mongodb .core .query .Update ;
4446import org .springframework .data .mongodb .core .query .UpdateDefinition ;
45- import org .springframework .data .util .CloseableIterator ;
4647import org .springframework .lang .Nullable ;
4748import org .springframework .util .Assert ;
4849import org .springframework .util .ClassUtils ;
@@ -225,34 +226,34 @@ public <T> T execute(SessionCallback<T> action, Consumer<ClientSession> onComple
225226 * Executes the given {@link Query} on the entity collection of the specified {@code entityType} backed by a Mongo DB
226227 * {@link com.mongodb.client.FindIterable}.
227228 * <p>
228- * Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to
229- * be closed.
229+ * Returns a {@link String} that wraps the Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
230230 *
231231 * @param query the query class that specifies the criteria used to find a record and also an optional fields
232232 * specification. Must not be {@literal null}.
233233 * @param entityType must not be {@literal null}.
234234 * @param <T> element return type
235- * @return will never be {@literal null}.
235+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
236+ * through a try-with-resources clause).
236237 * @since 1.7
237238 */
238- <T > CloseableIterator <T > stream (Query query , Class <T > entityType );
239+ <T > Stream <T > stream (Query query , Class <T > entityType );
239240
240241/**
241242 * Executes the given {@link Query} on the entity collection of the specified {@code entityType} and collection backed
242243 * by a Mongo DB {@link com.mongodb.client.FindIterable}.
243244 * <p>
244- * Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to
245- * be closed.
245+ * Returns a {@link Stream} that wraps the Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
246246 *
247247 * @param query the query class that specifies the criteria used to find a record and also an optional fields
248248 * specification. Must not be {@literal null}.
249249 * @param entityType must not be {@literal null}.
250250 * @param collectionName must not be {@literal null} or empty.
251251 * @param <T> element return type
252- * @return will never be {@literal null}.
252+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
253+ * through a try-with-resources clause).
253254 * @since 1.10
254255 */
255- <T > CloseableIterator <T > stream (Query query , Class <T > entityType , String collectionName );
256+ <T > Stream <T > stream (Query query , Class <T > entityType , String collectionName );
256257
257258/**
258259 * Create an uncapped collection with a name based on the provided entity class.
@@ -521,9 +522,9 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
521522/**
522523 * Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
523524 * <p>
524- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
525- * needs to be closed. The raw results will be mapped to the given entity class. The name of the inputCollection is
526- * derived from the inputType of the aggregation.
525+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
526+ * closed. The raw results will be mapped to the given entity class. The name of the inputCollection is derived from
527+ * the inputType of the aggregation.
527528 * <p>
528529 * Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
529530 * explanation mode will throw an {@link IllegalArgumentException}.
@@ -532,35 +533,37 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
532533 * {@literal null}.
533534 * @param collectionName The name of the input collection to use for the aggreation.
534535 * @param outputType The parametrized type of the returned list, must not be {@literal null}.
535- * @return The results of the aggregation operation.
536+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
537+ * through a try-with-resources clause).
536538 * @since 2.0
537539 */
538- <O > CloseableIterator <O > aggregateStream (TypedAggregation <?> aggregation , String collectionName , Class <O > outputType );
540+ <O > Stream <O > aggregateStream (TypedAggregation <?> aggregation , String collectionName , Class <O > outputType );
539541
540542/**
541543 * Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
542- * <br / >
543- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
544- * needs to be closed. The raw results will be mapped to the given entity class and are returned as stream. The name
545- * of the inputCollection is derived from the inputType of the aggregation.
546- * <br / >
544+ * <p >
545+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
546+ * closed. The raw results will be mapped to the given entity class and are returned as stream. The name of the
547+ * inputCollection is derived from the inputType of the aggregation.
548+ * <p >
547549 * Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
548550 * explanation mode will throw an {@link IllegalArgumentException}.
549551 *
550552 * @param aggregation The {@link TypedAggregation} specification holding the aggregation operations, must not be
551553 * {@literal null}.
552554 * @param outputType The parametrized type of the returned list, must not be {@literal null}.
553- * @return The results of the aggregation operation.
555+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
556+ * through a try-with-resources clause).
554557 * @since 2.0
555558 */
556- <O > CloseableIterator <O > aggregateStream (TypedAggregation <?> aggregation , Class <O > outputType );
559+ <O > Stream <O > aggregateStream (TypedAggregation <?> aggregation , Class <O > outputType );
557560
558561/**
559562 * Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
560- * <br / >
561- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
562- * needs to be closed. The raw results will be mapped to the given entity class.
563- * <br / >
563+ * <p >
564+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
565+ * closed. The raw results will be mapped to the given entity class.
566+ * <p >
564567 * Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
565568 * explanation mode will throw an {@link IllegalArgumentException}.
566569 *
@@ -569,17 +572,18 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
569572 * @param inputType the inputType where the aggregation operation will read from, must not be {@literal null} or
570573 * empty.
571574 * @param outputType The parametrized type of the returned list, must not be {@literal null}.
572- * @return The results of the aggregation operation.
575+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
576+ * through a try-with-resources clause).
573577 * @since 2.0
574578 */
575- <O > CloseableIterator <O > aggregateStream (Aggregation aggregation , Class <?> inputType , Class <O > outputType );
579+ <O > Stream <O > aggregateStream (Aggregation aggregation , Class <?> inputType , Class <O > outputType );
576580
577581/**
578582 * Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
579- * <br / >
580- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
581- * needs to be closed. The raw results will be mapped to the given entity class.
582- * <br / >
583+ * <p >
584+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
585+ * closed. The raw results will be mapped to the given entity class.
586+ * <p >
583587 * Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
584588 * explanation mode will throw an {@link IllegalArgumentException}.
585589 *
@@ -588,10 +592,11 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
588592 * @param collectionName the collection where the aggregation operation will read from, must not be {@literal null} or
589593 * empty.
590594 * @param outputType The parametrized type of the returned list, must not be {@literal null}.
591- * @return The results of the aggregation operation.
595+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
596+ * through a try-with-resources clause).
592597 * @since 2.0
593598 */
594- <O > CloseableIterator <O > aggregateStream (Aggregation aggregation , String collectionName , Class <O > outputType );
599+ <O > Stream <O > aggregateStream (Aggregation aggregation , String collectionName , Class <O > outputType );
595600
596601/**
597602 * Execute a map-reduce operation. The map-reduce operation will be formed with an output type of INLINE
0 commit comments