diff --git a/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlow.kt b/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlow.kt index c8da59450ad..8c3d09500a4 100644 --- a/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlow.kt +++ b/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlow.kt @@ -62,9 +62,10 @@ public class AggregateFlow(private val wrapped: AggregatePublisher) public fun timeoutMode(timeoutMode: TimeoutMode): AggregateFlow = apply { wrapped.timeoutMode(timeoutMode) } /** - * Aggregates documents according to the specified aggregation pipeline, which must end with a $out or $merge stage. + * Aggregates documents according to the specified aggregation pipeline, which must end with an `$out` or `$merge` + * stage. Calling this method is a preferred alternative to consuming this [AggregateFlow]. * - * @throws IllegalStateException if the pipeline does not end with a $out or $merge stage + * @throws IllegalStateException if the pipeline does not end with an `$out` or `$merge` stage * @see [$out stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) * @see [$merge stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) */ @@ -214,5 +215,11 @@ public class AggregateFlow(private val wrapped: AggregatePublisher) public suspend inline fun explain(verbosity: ExplainVerbosity? = null): R = explain(R::class.java, verbosity) + /** + * Requests [AggregateFlow] to start streaming data according to the specified aggregation pipeline. + * - If the aggregation pipeline ends with an `$out` or `$merge` stage, then finds all documents in the affected + * namespace and emits them. You may want to use [toCollection] instead. + * - Otherwise, emits no values. + */ public override suspend fun collect(collector: FlowCollector): Unit = wrapped.asFlow().collect(collector) } diff --git a/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlow.kt b/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlow.kt index 407f1b8fe39..68293a0ab5b 100644 --- a/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlow.kt +++ b/driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlow.kt @@ -33,6 +33,9 @@ import org.bson.conversions.Bson /** * Flow implementation for map reduce operations. * + * By default, the [MapReduceFlow] emits the results inline. You can write map-reduce output to a collection by using + * the [collectionName] and [toCollection] methods. + * * Note: Starting in MongoDB 5.0, map-reduce is deprecated, prefer Aggregation instead * * @param T The type of the result. @@ -65,9 +68,10 @@ public class MapReduceFlow(private val wrapped: MapReducePublisher) /** * Aggregates documents to a collection according to the specified map-reduce function with the given options, which - * must specify a non-inline result. + * must not emit results inline. Calling this method is a preferred alternative to consuming this [MapReduceFlow]. * * @throws IllegalStateException if a collection name to write the results to has not been specified + * @see collectionName */ public suspend fun toCollection() { wrapped.toCollection().awaitFirstOrNull() @@ -80,6 +84,7 @@ public class MapReduceFlow(private val wrapped: MapReducePublisher) * * @param collectionName the name of the collection that you want the map-reduce operation to write its output. * @return this + * @see toCollection */ public fun collectionName(collectionName: String): MapReduceFlow = apply { wrapped.collectionName(collectionName) @@ -205,5 +210,12 @@ public class MapReduceFlow(private val wrapped: MapReducePublisher) */ public fun collation(collation: Collation?): MapReduceFlow = apply { wrapped.collation(collation) } + /** + * Requests [MapReduceFlow] to start streaming data according to the specified map-reduce function with the given + * options. + * - If the aggregation produces results inline, then finds all documents in the affected namespace and emits them. + * You may want to use [toCollection] instead. + * - Otherwise, emits no values. + */ public override suspend fun collect(collector: FlowCollector): Unit = wrapped.asFlow().collect(collector) } diff --git a/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlowTest.kt b/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlowTest.kt index 07953277d5a..ab4b9694986 100644 --- a/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlowTest.kt +++ b/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/AggregateFlowTest.kt @@ -39,7 +39,8 @@ class AggregateFlowTest { @Test fun shouldHaveTheSameMethods() { - val jAggregatePublisherFunctions = AggregatePublisher::class.declaredFunctions.map { it.name }.toSet() - "first" + val jAggregatePublisherFunctions = + AggregatePublisher::class.declaredFunctions.map { it.name }.toSet() - "first" - "subscribe" val kAggregateFlowFunctions = AggregateFlow::class.declaredFunctions.map { it.name }.toSet() - "collect" assertEquals(jAggregatePublisherFunctions, kAggregateFlowFunctions) diff --git a/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlowTest.kt b/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlowTest.kt index b9ef9133e87..3a38b7e6460 100644 --- a/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlowTest.kt +++ b/driver-kotlin-coroutine/src/test/kotlin/com/mongodb/kotlin/client/coroutine/MapReduceFlowTest.kt @@ -38,7 +38,8 @@ import reactor.core.publisher.Mono class MapReduceFlowTest { @Test fun shouldHaveTheSameMethods() { - val jMapReducePublisherFunctions = MapReducePublisher::class.declaredFunctions.map { it.name }.toSet() - "first" + val jMapReducePublisherFunctions = + MapReducePublisher::class.declaredFunctions.map { it.name }.toSet() - "first" - "subscribe" val kMapReduceFlowFunctions = MapReduceFlow::class.declaredFunctions.map { it.name }.toSet() - "collect" assertEquals(jMapReducePublisherFunctions, kMapReduceFlowFunctions) diff --git a/driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/AggregateIterable.kt b/driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/AggregateIterable.kt index b5449a14645..4d36065607c 100644 --- a/driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/AggregateIterable.kt +++ b/driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/AggregateIterable.kt @@ -61,14 +61,23 @@ public class AggregateIterable(private val wrapped: JAggregateIterable< } /** - * Aggregates documents according to the specified aggregation pipeline, which must end with a $out or $merge stage. + * Aggregates documents according to the specified aggregation pipeline, which must end with an `$out` or `$merge` + * stage. This method is the preferred alternative to [cursor]. * - * @throws IllegalStateException if the pipeline does not end with a $out or $merge stage + * @throws IllegalStateException if the pipeline does not end with an `$out` or `$merge` stage * @see [$out stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) * @see [$merge stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) */ public fun toCollection(): Unit = wrapped.toCollection() + /** + * Aggregates documents according to the specified aggregation pipeline. + * - If the aggregation pipeline ends with an `$out` or `$merge` stage, then finds all documents in the affected + * namespace and returns a [MongoCursor] over them. You may want to use [toCollection] instead. + * - Otherwise, returns a [MongoCursor] producing no elements. + */ + public override fun cursor(): MongoCursor = super.cursor() + /** * Enables writing to temporary files. A null value indicates that it's unspecified. * diff --git a/driver-kotlin-sync/src/test/kotlin/com/mongodb/kotlin/client/AggregateIterableTest.kt b/driver-kotlin-sync/src/test/kotlin/com/mongodb/kotlin/client/AggregateIterableTest.kt index 89cc8db421e..83ca9bce0ad 100644 --- a/driver-kotlin-sync/src/test/kotlin/com/mongodb/kotlin/client/AggregateIterableTest.kt +++ b/driver-kotlin-sync/src/test/kotlin/com/mongodb/kotlin/client/AggregateIterableTest.kt @@ -37,7 +37,8 @@ class AggregateIterableTest { @Test fun shouldHaveTheSameMethods() { - val jAggregateIterableFunctions = JAggregateIterable::class.declaredFunctions.map { it.name }.toSet() + val jAggregateIterableFunctions = + JAggregateIterable::class.declaredFunctions.map { it.name }.toSet() - "iterator" val kAggregateIterableFunctions = AggregateIterable::class.declaredFunctions.map { it.name }.toSet() assertEquals(jAggregateIterableFunctions, kAggregateIterableFunctions) diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/AggregatePublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/AggregatePublisher.java index 0642d0fc8f9..c0ea254aeb3 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/AggregatePublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/AggregatePublisher.java @@ -17,15 +17,19 @@ package com.mongodb.reactivestreams.client; import com.mongodb.ExplainVerbosity; +import com.mongodb.MongoNamespace; import com.mongodb.annotations.Alpha; import com.mongodb.annotations.Reason; import com.mongodb.client.cursor.TimeoutMode; +import com.mongodb.client.model.Aggregates; import com.mongodb.client.model.Collation; +import com.mongodb.client.model.MergeOptions; import com.mongodb.lang.Nullable; import org.bson.BsonValue; import org.bson.Document; import org.bson.conversions.Bson; import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; import java.util.concurrent.TimeUnit; @@ -83,13 +87,31 @@ public interface AggregatePublisher extends Publisher { AggregatePublisher bypassDocumentValidation(@Nullable Boolean bypassDocumentValidation); /** - * Aggregates documents according to the specified aggregation pipeline, which must end with a $out stage. + * Aggregates documents according to the specified aggregation pipeline, which must end with an + * {@link Aggregates#out(String, String) $out} or {@link Aggregates#merge(MongoNamespace, MergeOptions) $merge} stage. + * Calling this method and then {@linkplain Publisher#subscribe(Subscriber) subscribing} to the returned {@link Publisher} + * is a preferred alternative to {@linkplain #subscribe(Subscriber) subscribing} to this {@link AggregatePublisher}. * + * @throws IllegalStateException if the pipeline does not end with an {@code $out} or {@code $merge} stage * @return an empty publisher that indicates when the operation has completed * @mongodb.driver.manual aggregation/ Aggregation */ Publisher toCollection(); + /** + * Requests {@link AggregatePublisher} to start streaming data according to the specified aggregation pipeline. + *
    + *
  • + * If the aggregation pipeline ends with an {@link Aggregates#out(String, String) $out} or + * {@link Aggregates#merge(MongoNamespace, MergeOptions) $merge} stage, + * then {@linkplain MongoCollection#find() finds all} documents in the affected namespace and produces them. + * You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, produces no elements.
  • + *
+ */ + void subscribe(Subscriber s); + /** * Sets the collation options * diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/MapReducePublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/MapReducePublisher.java index 2add0f33691..7ca2c959e49 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/MapReducePublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/MapReducePublisher.java @@ -16,7 +16,6 @@ package com.mongodb.reactivestreams.client; - import com.mongodb.annotations.Alpha; import com.mongodb.annotations.Reason; import com.mongodb.client.cursor.TimeoutMode; @@ -24,11 +23,15 @@ import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; import java.util.concurrent.TimeUnit; /** * Publisher for map reduce. + *

+ * By default, the {@code MapReducePublisher} produces the results inline. You can write map-reduce output to a collection by using the + * {@link #collectionName(String)} and {@link #toCollection()} methods.

* * @param The type of the result. * @since 1.0 @@ -44,6 +47,7 @@ public interface MapReducePublisher extends Publisher { * * @param collectionName the name of the collection that you want the map-reduce operation to write its output. * @return this + * @see #toCollection() */ MapReducePublisher collectionName(String collectionName); @@ -152,14 +156,29 @@ public interface MapReducePublisher extends Publisher { MapReducePublisher bypassDocumentValidation(@Nullable Boolean bypassDocumentValidation); /** - * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a - * non-inline result. + * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must not produce + * results inline. Calling this method and then {@linkplain Publisher#subscribe(Subscriber) subscribing} to the returned + * {@link Publisher} is a preferred alternative to {@linkplain #subscribe(Subscriber) subscribing} to this {@link MapReducePublisher}. * * @return an empty publisher that indicates when the operation has completed + * @throws IllegalStateException if a {@linkplain #collectionName(String) collection name} to write the results to has not been specified + * @see #collectionName(String) * @mongodb.driver.manual aggregation/ Aggregation */ Publisher toCollection(); + /** + * Requests {@link MapReducePublisher} to start streaming data according to the specified map-reduce function with the given options. + *
    + *
  • + * If the aggregation produces results inline, then {@linkplain MongoCollection#find() finds all} documents in the + * affected namespace and produces them. You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, produces no elements.
  • + *
+ */ + void subscribe(Subscriber s); + /** * Sets the collation options * diff --git a/driver-scala/src/main/scala/org/mongodb/scala/AggregateObservable.scala b/driver-scala/src/main/scala/org/mongodb/scala/AggregateObservable.scala index d496a4ab8a2..de839491131 100644 --- a/driver-scala/src/main/scala/org/mongodb/scala/AggregateObservable.scala +++ b/driver-scala/src/main/scala/org/mongodb/scala/AggregateObservable.scala @@ -25,6 +25,7 @@ import org.mongodb.scala.bson.BsonValue import org.mongodb.scala.bson.DefaultHelper.DefaultsTo import org.mongodb.scala.bson.conversions.Bson import org.mongodb.scala.model.Collation +import org.reactivestreams.Subscriber import scala.concurrent.duration.Duration import scala.reflect.ClassTag @@ -192,9 +193,13 @@ case class AggregateObservable[TResult](private val wrapped: AggregatePublisher[ } /** - * Aggregates documents according to the specified aggregation pipeline, which must end with a `\$out` stage. + * Aggregates documents according to the specified aggregation pipeline, which must end with an `\$out` or `\$merge` stage. + * Calling this method and then `subscribing` to the returned [[SingleObservable]] + * is a preferred alternative to subscribing to this [[AggregateObservable]]. * * [[https://www.mongodb.com/docs/manual/aggregation/ Aggregation]] + * + * @throws java.lang.IllegalStateException if the pipeline does not end with an `\$out` or `\$merge` stage * @return an Observable that indicates when the operation has completed. */ def toCollection(): SingleObservable[Unit] = wrapped.toCollection() @@ -257,5 +262,23 @@ case class AggregateObservable[TResult](private val wrapped: AggregatePublisher[ )(implicit e: ExplainResult DefaultsTo Document, ct: ClassTag[ExplainResult]): SingleObservable[ExplainResult] = wrapped.explain[ExplainResult](ct, verbosity) + /** + * Requests [[AggregateObservable]] to start streaming data according to the specified aggregation pipeline. + * + * - If the aggregation pipeline ends with an `\$out` or `\$merge` stage, + * then finds all documents in the affected namespace and produces them. + * You may want to use [[toCollection]] instead. + * - Otherwise, produces no elements. + */ override def subscribe(observer: Observer[_ >: TResult]): Unit = wrapped.subscribe(observer) + + /** + * Requests [[AggregateObservable]] to start streaming data according to the specified aggregation pipeline. + * + * - If the aggregation pipeline ends with an `\$out` or `\$merge` stage, + * then finds all documents in the affected namespace and produces them. + * You may want to use [[toCollection]] instead. + * - Otherwise, produces no elements. + */ + override def subscribe(observer: Subscriber[_ >: TResult]): Unit = wrapped.subscribe(observer) } diff --git a/driver-scala/src/main/scala/org/mongodb/scala/MapReduceObservable.scala b/driver-scala/src/main/scala/org/mongodb/scala/MapReduceObservable.scala index 0ed78bb775b..941ad68ddd9 100644 --- a/driver-scala/src/main/scala/org/mongodb/scala/MapReduceObservable.scala +++ b/driver-scala/src/main/scala/org/mongodb/scala/MapReduceObservable.scala @@ -23,12 +23,16 @@ import com.mongodb.client.model.MapReduceAction import com.mongodb.reactivestreams.client.MapReducePublisher import org.mongodb.scala.bson.conversions.Bson import org.mongodb.scala.model.Collation +import org.reactivestreams.Subscriber import scala.concurrent.duration.Duration /** * Observable for map reduce. * + * By default, the [[MapReduceObservable]] produces the results inline. You can write map-reduce output to a collection by using the + * [[collectionName]] and [[toCollection]] methods. + * * @define docsRef https://www.mongodb.com/docs/manual/reference * * @tparam TResult The type of the result. @@ -44,6 +48,7 @@ case class MapReduceObservable[TResult](wrapped: MapReducePublisher[TResult]) ex * * @param collectionName the name of the collection that you want the map-reduce operation to write its output. * @return this + * @see [[toCollection]] */ def collectionName(collectionName: String): MapReduceObservable[TResult] = { wrapped.collectionName(collectionName) @@ -214,11 +219,14 @@ case class MapReduceObservable[TResult](wrapped: MapReducePublisher[TResult]) ex } /** - * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a - * non-inline result. + * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must not produce + * results inline. Calling this method and then subscribing to the returned [[SingleObservable]] is a preferred alternative to + * subscribing to this [[MapReduceObservable]]. * * @return an Observable that indicates when the operation has completed * [[https://www.mongodb.com/docs/manual/aggregation/ Aggregation]] + * @throws java.lang.IllegalStateException if a collection name to write the results to has not been specified + * @see [[collectionName]] */ def toCollection(): SingleObservable[Unit] = wrapped.toCollection() @@ -246,5 +254,21 @@ case class MapReduceObservable[TResult](wrapped: MapReducePublisher[TResult]) ex */ def first(): SingleObservable[TResult] = wrapped.first() + /** + * Requests [[MapReduceObservable]] to start streaming data according to the specified map-reduce function with the given options. + * + * - If the aggregation produces results inline, then finds all documents in the + * affected namespace and produces them. You may want to use [[toCollection]] instead. + * - Otherwise, produces no elements. + */ override def subscribe(observer: Observer[_ >: TResult]): Unit = wrapped.subscribe(observer) + + /** + * Requests [[MapReduceObservable]] to start streaming data according to the specified map-reduce function with the given options. + * + * - If the aggregation produces results inline, then finds all documents in the + * affected namespace and produces them. You may want to use [[toCollection]] instead. + * - Otherwise, produces no elements. + */ + override def subscribe(observer: Subscriber[_ >: TResult]): Unit = wrapped.subscribe(observer) } diff --git a/driver-sync/src/main/com/mongodb/client/AggregateIterable.java b/driver-sync/src/main/com/mongodb/client/AggregateIterable.java index 5f7a0dc2aff..6eaf50e7061 100644 --- a/driver-sync/src/main/com/mongodb/client/AggregateIterable.java +++ b/driver-sync/src/main/com/mongodb/client/AggregateIterable.java @@ -17,10 +17,13 @@ package com.mongodb.client; import com.mongodb.ExplainVerbosity; +import com.mongodb.MongoNamespace; import com.mongodb.annotations.Alpha; import com.mongodb.annotations.Reason; import com.mongodb.client.cursor.TimeoutMode; +import com.mongodb.client.model.Aggregates; import com.mongodb.client.model.Collation; +import com.mongodb.client.model.MergeOptions; import com.mongodb.lang.Nullable; import org.bson.BsonValue; import org.bson.Document; @@ -38,15 +41,47 @@ public interface AggregateIterable extends MongoIterable { /** - * Aggregates documents according to the specified aggregation pipeline, which must end with a $out or $merge stage. + * Aggregates documents according to the specified aggregation pipeline, which must end with an + * {@link Aggregates#out(String, String) $out} or {@link Aggregates#merge(MongoNamespace, MergeOptions) $merge} stage. + * This method is the preferred alternative to {@link #iterator()}, {@link #cursor()}. * - * @throws IllegalStateException if the pipeline does not end with a $out or $merge stage + * @throws IllegalStateException if the pipeline does not end with an {@code $out} or {@code $merge} stage * @mongodb.driver.manual reference/operator/aggregation/out/ $out stage * @mongodb.driver.manual reference/operator/aggregation/merge/ $merge stage * @since 3.4 */ void toCollection(); + /** + * Aggregates documents according to the specified aggregation pipeline. + *
    + *
  • + * If the aggregation pipeline ends with an {@link Aggregates#out(String, String) $out} or + * {@link Aggregates#merge(MongoNamespace, MergeOptions) $merge} stage, + * then {@linkplain MongoCollection#find() finds all} documents in the affected namespace and returns a {@link MongoCursor} + * over them. You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, returns a {@link MongoCursor} producing no elements.
  • + *
+ */ + @Override + MongoCursor iterator(); + + /** + * Aggregates documents according to the specified aggregation pipeline. + *
    + *
  • + * If the aggregation pipeline ends with an {@link Aggregates#out(String, String) $out} or + * {@link Aggregates#merge(MongoNamespace, MergeOptions) $merge} stage, + * then {@linkplain MongoCollection#find() finds all} documents in the affected namespace and returns a {@link MongoCursor} + * over them. You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, returns a {@link MongoCursor} producing no elements.
  • + *
+ */ + @Override + MongoCursor cursor(); + /** * Enables writing to temporary files. A null value indicates that it's unspecified. * diff --git a/driver-sync/src/main/com/mongodb/client/MapReduceIterable.java b/driver-sync/src/main/com/mongodb/client/MapReduceIterable.java index d406e785da7..35a3006c4d3 100644 --- a/driver-sync/src/main/com/mongodb/client/MapReduceIterable.java +++ b/driver-sync/src/main/com/mongodb/client/MapReduceIterable.java @@ -27,9 +27,9 @@ /** * Iterable for map-reduce. - * - *

By default the {@code MapReduceIterable} returns the results inline. You can write map-reduce output to a collection by using the - * {@link MapReduceIterable#collectionName(String)} method.

+ *

+ * By default, the {@code MapReduceIterable} produces the results inline. You can write map-reduce output to a collection by using the + * {@link #collectionName(String)} and {@link #toCollection()} methods.

* * @param The type of the result. * @since 3.0 @@ -39,15 +39,41 @@ public interface MapReduceIterable extends MongoIterable { /** - * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a - * non-inline result. + * Aggregates documents to a collection according to the specified map-reduce function with the given options, which must not produce + * results inline. This method is the preferred alternative to {@link #iterator()}, {@link #cursor()}. * - * @throws IllegalStateException if a collection name to write the results to has not been specified + * @throws IllegalStateException if a {@linkplain #collectionName(String) collection name} to write the results to has not been specified * @see #collectionName(String) * @since 3.4 */ void toCollection(); + /** + * Aggregates documents according to the specified map-reduce function with the given options. + *
    + *
  • + * If the aggregation produces results inline, then {@linkplain MongoCollection#find() finds all} documents in the + * affected namespace and returns a {@link MongoCursor} over them. You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, returns a {@link MongoCursor} producing no elements.
  • + *
+ */ + @Override + MongoCursor iterator(); + + /** + * Aggregates documents according to the specified map-reduce function with the given options. + *
    + *
  • + * If the aggregation produces results inline, then {@linkplain MongoCollection#find() finds all} documents in the + * affected namespace and returns a {@link MongoCursor} over them. You may want to use {@link #toCollection()} instead.
  • + *
  • + * Otherwise, returns a {@link MongoCursor} producing no elements.
  • + *
+ */ + @Override + MongoCursor cursor(); + /** * Sets the collectionName for the output of the MapReduce * @@ -55,6 +81,7 @@ public interface MapReduceIterable extends MongoIterable { * * @param collectionName the name of the collection that you want the map-reduce operation to write its output. * @return this + * @see #toCollection() */ MapReduceIterable collectionName(String collectionName); diff --git a/driver-sync/src/main/com/mongodb/client/MongoIterable.java b/driver-sync/src/main/com/mongodb/client/MongoIterable.java index 06bec548c77..e69d499c8f7 100644 --- a/driver-sync/src/main/com/mongodb/client/MongoIterable.java +++ b/driver-sync/src/main/com/mongodb/client/MongoIterable.java @@ -29,13 +29,16 @@ */ public interface MongoIterable extends Iterable { + /** + * @return A {@link MongoCursor} that must be {@linkplain MongoCursor#close() closed}. + */ @Override MongoCursor iterator(); /** * Returns a cursor used for iterating over elements of type {@code TResult}. The cursor is primarily used for change streams. * - * @return a cursor + * @return a cursor equivalent to that returned from {@link #iterator()}. * @since 3.11 */ MongoCursor cursor();