diff --git a/backend-services/feed-service/app/utils/MongoConnection.scala b/backend-services/feed-service/app/utils/MongoConnection.scala index 39caedb80c63b68cb573ce00e052067552f8800f..04ca348a8010d87e0ee83621819b28d8a6b3b3ab 100644 --- a/backend-services/feed-service/app/utils/MongoConnection.scala +++ b/backend-services/feed-service/app/utils/MongoConnection.scala @@ -1,7 +1,7 @@ package utils import org.mongodb.scala.{MongoClient, MongoDatabase, MongoCollection} -import org.mongodb.scala.model.{Filters, Projections, Sorts} +import org.mongodb.scala.model.{Filters, Sorts} import com.mongodb.client.result.{InsertOneResult, UpdateResult} import org.bson.conversions.Bson @@ -63,13 +63,17 @@ object MongoConnection { def find[T: ClassTag]( collection: MongoCollection[T], filter: Bson = Filters.empty(), - projection: Bson = Projections.excludeId(), - sort: Bson = Sorts.ascending("_id") + sort: Bson = Sorts.ascending("_id"), + projection: Option[Bson] = None ): Future[Seq[T]] = { - collection.find[T](filter) - .projection(projection) - .sort(sort) - .toFuture() + var result = collection.find[T](filter).sort(sort) + + result = if (projection.isDefined == true) + result.projection(projection.get) + else + result + + result.toFuture() } /**