diff --git a/driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java b/driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java index b9e92427dbd..3b25cb69692 100644 --- a/driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java @@ -59,6 +59,7 @@ public Bson getProjection() { * @param projection the project document, which may be null. * @return this * @mongodb.driver.manual tutorial/project-fields-from-query-results Projection + * @see Projections */ public FindOneAndDeleteOptions projection(@Nullable final Bson projection) { this.projection = projection; diff --git a/driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java b/driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java index 5f7319d64e3..fe17d4f24bd 100644 --- a/driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java @@ -62,6 +62,7 @@ public Bson getProjection() { * @param projection the project document, which may be null. * @return this * @mongodb.driver.manual tutorial/project-fields-from-query-results Projection + * @see Projections */ public FindOneAndReplaceOptions projection(@Nullable final Bson projection) { this.projection = projection; diff --git a/driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java b/driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java index ce370b88a16..a850bdcc0f2 100644 --- a/driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java @@ -64,6 +64,7 @@ public Bson getProjection() { * @param projection the project document, which may be null. * @return this * @mongodb.driver.manual tutorial/project-fields-from-query-results Projection + * @see Projections */ public FindOneAndUpdateOptions projection(@Nullable final Bson projection) { this.projection = projection; diff --git a/driver-core/src/main/com/mongodb/client/model/Projections.java b/driver-core/src/main/com/mongodb/client/model/Projections.java index 6ef7bc99729..e92a95abf81 100644 --- a/driver-core/src/main/com/mongodb/client/model/Projections.java +++ b/driver-core/src/main/com/mongodb/client/model/Projections.java @@ -52,8 +52,20 @@ private Projections() { } /** - * Creates a projection of a field whose value is computed from the given expression. Projection with an expression is only supported - * using the $project aggregation pipeline stage. + * Creates a projection of a field whose value is computed from the given expression. Projection with an expression can be used in the + * following contexts: + * * * @param fieldName the field name * @param expression the expression diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/FindPublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/FindPublisher.java index 3ce47cbf17d..d7ec41a1bfb 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/FindPublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/FindPublisher.java @@ -19,6 +19,7 @@ import com.mongodb.CursorType; import com.mongodb.ExplainVerbosity; import com.mongodb.client.model.Collation; +import com.mongodb.client.model.Projections; import com.mongodb.lang.Nullable; import org.bson.BsonValue; import org.bson.Document; @@ -104,6 +105,7 @@ public interface FindPublisher extends Publisher { * @param projection the project document, which may be null. * @return this * @mongodb.driver.manual reference/method/db.collection.find/ Projection + * @see Projections */ FindPublisher projection(@Nullable Bson projection); /** diff --git a/driver-scala/src/main/scala/org/mongodb/scala/FindObservable.scala b/driver-scala/src/main/scala/org/mongodb/scala/FindObservable.scala index f12593c9fc8..2d147a42211 100644 --- a/driver-scala/src/main/scala/org/mongodb/scala/FindObservable.scala +++ b/driver-scala/src/main/scala/org/mongodb/scala/FindObservable.scala @@ -121,6 +121,7 @@ case class FindObservable[TResult](private val wrapped: FindPublisher[TResult]) * [[https://www.mongodb.com/docs/manual/reference/method/db.collection.find/ Projection]] * @param projection the project document, which may be null. * @return this + * @see [[org.mongodb.scala.model.Projections]] */ def projection(projection: Bson): FindObservable[TResult] = { wrapped.projection(projection) diff --git a/driver-scala/src/main/scala/org/mongodb/scala/model/Projections.scala b/driver-scala/src/main/scala/org/mongodb/scala/model/Projections.scala index 989258aaa59..7da4a853544 100644 --- a/driver-scala/src/main/scala/org/mongodb/scala/model/Projections.scala +++ b/driver-scala/src/main/scala/org/mongodb/scala/model/Projections.scala @@ -32,8 +32,20 @@ import org.mongodb.scala.bson.conversions.Bson object Projections { /** - * Creates a projection of a field whose value is computed from the given expression. Projection with an expression is only supported - * using the `\$project` aggregation pipeline stage. + * Creates a projection of a field whose value is computed from the given expression. Projection with an expression can be used in the + * following contexts: + *
    + *
  • $project aggregation pipeline stage.
  • + *
  • Starting from MongoDB 4.4, it's also accepted in various find-related methods within the + * `MongoCollection`-based API where projection is supported, for example: + *
      + *
    • `find()`
    • + *
    • `findOneAndReplace()`
    • + *
    • `findOneAndUpdate()`
    • + *
    • `findOneAndDelete()`
    • + *
    + *
  • + *
* * @param fieldName the field name * @param expression the expression diff --git a/driver-sync/src/main/com/mongodb/client/FindIterable.java b/driver-sync/src/main/com/mongodb/client/FindIterable.java index affabf0df5b..3ea23c178c1 100644 --- a/driver-sync/src/main/com/mongodb/client/FindIterable.java +++ b/driver-sync/src/main/com/mongodb/client/FindIterable.java @@ -19,6 +19,7 @@ import com.mongodb.CursorType; import com.mongodb.ExplainVerbosity; import com.mongodb.client.model.Collation; +import com.mongodb.client.model.Projections; import com.mongodb.lang.Nullable; import org.bson.BsonValue; import org.bson.Document; @@ -96,6 +97,7 @@ public interface FindIterable extends MongoIterable { * @param projection the project document, which may be null. * @return this * @mongodb.driver.manual reference/method/db.collection.find/ Projection + * @see Projections */ FindIterable projection(@Nullable Bson projection);