t

reactivemongo.api.collections

GenericCollection

trait GenericCollection[P <: SerializationPack] extends Collection with PackSupport[P] with GenericCollectionWithCommands[P] with CollectionMetaCommands with InsertOps[P] with UpdateOps[P] with DeleteOps[P] with CountOp[P] with DistinctOp[P] with GenericCollectionWithDistinctOps[P] with FindAndModifyOps[P] with ChangeStreamOps[P] with AggregationOps[P] with GenericCollectionMetaCommands[P] with QueryBuilderFactory[P]

A Collection that provides default methods using a SerializationPack.

Some methods of this collection accept instances of Reader[T] and Writer[T], that transform any T instance into a document, compatible with the selected serialization pack, and vice-versa.

P

the serialization pack

Self Type
GenericCollection[P]
Linear Supertypes
QueryBuilderFactory[P], HintFactory[P], GenericCollectionMetaCommands[P], AggregationOps[P], ChangeStreamOps[P], FindAndModifyOps[P], FindAndModifyCommand[P], GenericCollectionWithDistinctOps[P], DistinctOp[P], DistinctOpCompat[P], CountOp[P], DeleteOps[P], DeleteCommand[P], UpdateOps[P], UpdateWriteResultFactory[P], UpdateCommand[P], InsertOps[P], LastErrorFactory[P], UpsertedFactory[P], MultiBulkWriteResultFactory[P], CommandCodecsWithPack[P], InsertCommand[P], CollectionMetaCommands, GenericCollectionWithCommands[P], PackSupport[P], Collection, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. GenericCollection
  2. QueryBuilderFactory
  3. HintFactory
  4. GenericCollectionMetaCommands
  5. AggregationOps
  6. ChangeStreamOps
  7. FindAndModifyOps
  8. FindAndModifyCommand
  9. GenericCollectionWithDistinctOps
  10. DistinctOp
  11. DistinctOpCompat
  12. CountOp
  13. DeleteOps
  14. DeleteCommand
  15. UpdateOps
  16. UpdateWriteResultFactory
  17. UpdateCommand
  18. InsertOps
  19. LastErrorFactory
  20. UpsertedFactory
  21. MultiBulkWriteResultFactory
  22. CommandCodecsWithPack
  23. InsertCommand
  24. CollectionMetaCommands
  25. GenericCollectionWithCommands
  26. PackSupport
  27. Collection
  28. AnyRef
  29. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class AggregatorContext[T] extends AnyRef

    Aggregator context

    Aggregator context

    Definition Classes
    AggregationOps
  2. sealed trait WatchBuilder[T] extends AnyRef

    A builder for the watch collection helper, which allows to consume the collection's ChangeStream.

    A builder for the watch collection helper, which allows to consume the collection's ChangeStream.

    Definition Classes
    ChangeStreamOps
  3. sealed trait DeleteBuilder extends AnyRef

    Builder for delete operations.

    Builder for delete operations.

    Definition Classes
    DeleteOps
  4. final type AggregationFramework = AggregationFramework.type

    Aggregation framework

    Aggregation framework

    Definition Classes
    AggregationOps
  5. final type DeleteCmd = ResolvedCollectionCommand[Delete]
    Attributes
    protected
    Definition Classes
    DeleteCommand
  6. final class DeleteElement extends AnyRef

    Delete command element

    Delete command element

    Definition Classes
    DeleteCommand
  7. final type DeleteResult = DefaultWriteResult

    Result for a delete command

    Result for a delete command

    Definition Classes
    DeleteCommand
  8. case class DistinctResult extends Product with Serializable

    Attributes
    protected
    Definition Classes
    DistinctOp
  9. final type FindAndModifyCmd = ResolvedCollectionCommand[FindAndModify]
    Attributes
    protected[reactivemongo]
    Definition Classes
    FindAndModifyCommand
  10. sealed trait Hint extends AnyRef

    An index hint

    An index hint

    Definition Classes
    HintFactory
  11. final type PipelineOperator = AggregationOps.AggregationFramework.PipelineOperator

    Aggregation pipeline operator/stage

    Aggregation pipeline operator/stage

    Definition Classes
    AggregationOps
  12. final type UpdateCmd = ResolvedCollectionCommand[Update]
    Attributes
    protected[reactivemongo]
    Definition Classes
    UpdateCommand
  13. final class UpdateElement extends AnyRef

    Definition Classes
    UpdateCommand
  14. final class UpdateWriteResult extends WriteResult

    Result for the update operations.

    Result for the update operations.

    Definition Classes
    UpdateWriteResultFactory
  15. sealed trait InsertBuilder extends AnyRef

    Builder for insert operations.

    Builder for insert operations.

    Definition Classes
    InsertOps
  16. final class QueryBuilder extends AnyRef

    A builder that helps to make a fine-tuned query to MongoDB.

    A builder that helps to make a fine-tuned query to MongoDB.

    When the query is ready, you can call cursor to get a Cursor, or one if you want to retrieve just one document.

    Definition Classes
    QueryBuilderFactory
  17. sealed trait UpdateBuilder extends AnyRef

    Builder for update operations.

    Builder for update operations.

    Definition Classes
    UpdateOps
  18. sealed trait FindAndModifyOp extends AnyRef

    A modify operation, part of a FindAndModify command

    A modify operation, part of a FindAndModify command

    Definition Classes
    FindAndModifyCommand
  19. final class FindAndModifyResult extends AnyRef

    Result for a find-and-modify command

    Result for a find-and-modify command

    Definition Classes
    FindAndModifyCommand
  20. final class FindAndUpdateLastError extends AnyRef

    Last error for a find-and-update command

    Last error for a find-and-update command

    Definition Classes
    FindAndModifyCommand
  21. final class FindAndUpdateOp extends (FindAndModifyCommand.this)#FindAndModifyOp

    Update (part of a FindAndModify command).

    Update (part of a FindAndModify command).

    Definition Classes
    FindAndModifyCommand
  22. final class MultiBulkWriteResult extends AnyRef

    The result of a bulk write operation.

    The result of a bulk write operation.

    Definition Classes
    MultiBulkWriteResultFactory
  23. final class Upserted extends AnyRef

    An upserted element

    An upserted element

    Definition Classes
    UpsertedFactory

Abstract Value Members

  1. abstract def db: DB

    The database which this collection belongs to.

    The database which this collection belongs to.

    Definition Classes
    Collection
  2. abstract def name: String

    The name of the collection.

    The name of the collection.

    Definition Classes
    Collection
  3. abstract val pack: P

    The serialization pack (BSON by default).

    The serialization pack (BSON by default).

    Used to resolve the types of values (by default BSONValue, BSONDocument, ...), and the related typeclasses (e.g. BSONDocumentReader ...).

    Definition Classes
    PackSupport
  4. abstract def readPreference: ReadPreference

    The default read preference

    The default read preference

    Annotations
    @inline()
  5. abstract def withReadPreference(pref: ReadPreference): GenericCollection[P]

    Returns a new reference to the same collection, with the given read preference.

Concrete Value Members

  1. object AggregationFramework extends commands.AggregationFramework[GenericCollection.pack.type] with PackSupport[GenericCollection.pack.type]

    The aggregation framework for this collection

    The aggregation framework for this collection

    Definition Classes
    AggregationOps
  2. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  3. final def ##: Int
    Definition Classes
    AnyRef → Any
  4. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toany2stringadd[GenericCollection[P]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  5. def ->[B](y: B): (GenericCollection[P], B)
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toArrowAssoc[GenericCollection[P]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def aggregateWith[T](explain: Boolean = false, allowDiskUse: Boolean = false, bypassDocumentValidation: Boolean = false, readConcern: ReadConcern = this.readConcern, readPreference: ReadPreference = ReadPreference.primary, batchSize: Option[Int] = None)(f: (AggregationFramework) => AggregationOps.AggregationFramework.Pipeline)(implicit reader: P.Reader[T], cp: CursorProducer[T]): ProducedCursor

    Aggregates the matching documents.

    Aggregates the matching documents.

    T

    The type of the result elements. An implicit Reader[T] typeclass for handling it has to be in the scope.

    explain

    if true indicates to return the information on the processing of the pipeline

    allowDiskUse

    if true enables writing to temporary files

    bypassDocumentValidation

    the flag to bypass document validation during the operation (default: false)

    readConcern

    the read concern

    readPreference

    the read preference for the result (default: primary)

    batchSize

    the batch size (for the aggregation cursor; if None use the default one)

    f

    the function to create the aggregation pipeline using the aggregation framework depending on the collection type

    reader

    the result reader

  8. def aggregatorContext[T](pipeline: List[PipelineOperator] = List.empty, explain: Boolean = false, allowDiskUse: Boolean = false, bypassDocumentValidation: Boolean = false, readConcern: ReadConcern = this.readConcern, readPreference: ReadPreference = this.readPreference, writeConcern: WriteConcern = this.writeConcern, batchSize: Option[Int] = None, cursorOptions: CursorOptions = CursorOptions.empty, maxTime: Option[FiniteDuration] = None, hint: Option[Hint] = None, comment: Option[String] = None, collation: Option[Collation] = None)(implicit reader: P.Reader[T]): AggregatorContext[T]

    Aggregates the matching documents.

    Aggregates the matching documents.

    import scala.concurrent.Future
    import scala.concurrent.ExecutionContext.Implicits.global
    
    import reactivemongo.api.Cursor
    import reactivemongo.api.bson._
    import reactivemongo.api.bson.collection.BSONCollection
    
    def populatedStates(cities: BSONCollection): Future[List[BSONDocument]] = {
      import cities.AggregationFramework
      import AggregationFramework.{ Group, Match, SumField }
    
      cities.aggregatorContext[BSONDocument](
        List(Group(BSONString(f"$$state"))(
          "totalPop" -> SumField("population")),
            Match(BSONDocument("totalPop" ->
              BSONDocument(f"$$gte" -> 10000000L))))
      ).prepared.cursor.collect[List](
        maxDocs = 3,
        err = Cursor.FailOnError[List[BSONDocument]]()
      )
    }
    T

    The type of the result elements. An implicit Reader[T] typeclass for handling it has to be in the scope.

    explain

    if true indicates to return the information on the processing of the pipeline (default: false)

    allowDiskUse

    if true enables writing to temporary files (default: false)

    bypassDocumentValidation

    the flag to bypass document validation during the operation (default: false)

    readConcern

    the read concern

    readPreference

    the read preference for the result

    writeConcern

    the writer concern to be used

    batchSize

    the batch size (for the aggregation cursor; if None use the default one)

    cursorOptions

    the options for the result cursor

    maxTime

    the time limit for processing operations on a cursor (maxTimeMS)

    hint

    the index to use (either the index name or the index document)

    comment

    the comment to annotation the aggregation command

    collation

    the collation

    reader

    the result reader

    Annotations
    @SuppressWarnings()
  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  11. final def convertToCapped(size: Long, maxDocuments: Option[Int])(implicit ec: ExecutionContext): Future[Unit]

    Converts this collection to a capped one.

    Converts this collection to a capped one.

    import scala.concurrent.{ ExecutionContext, Future }
    
    def capColl(coll: reactivemongo.api.bson.collection.BSONCollection)(
      implicit ec: ExecutionContext): Future[Unit] =
      coll.convertToCapped(size = 10L, maxDocuments = Some(100))
    size

    the size of the collection (number of bytes)

    maxDocuments

    the maximum number of documents this capped collection can contain

    Definition Classes
    CollectionMetaCommands
  12. def count(selector: Option[P.Document] = None, limit: Option[Int] = None, skip: Int = 0, hint: Option[Hint] = None, readConcern: ReadConcern = this.readConcern, readPreference: ReadPreference = this.readPreference)(implicit ec: ExecutionContext): Future[Long]

    Counts the matching documents.

    Counts the matching documents.

    selector

    the document selector

    limit

    the maximum number of matching documents to count

    skip

    the number of matching documents to skip before counting

    hint

    the index to use (either the index name or the index document; see hint(..))

    readConcern

    the read concern

    readPreference

    the read preference for the result

    See also

    MongoDB documentation

  13. def countDocuments(query: Option[P.Document], limit: Option[Int], skip: Int, hint: Option[Hint], readConcern: ReadConcern, readPreference: ReadPreference)(implicit ec: ExecutionContext): Future[Long]
    Attributes
    protected[api]
    Definition Classes
    CountOp
  14. final def create(failsIfExists: Boolean = false, writeConcern: WriteConcern = db.defaultWriteConcern)(implicit ec: ExecutionContext): Future[Unit]

    Creates this collection.

    Creates this collection.

    import scala.concurrent.{ ExecutionContext, Future }
    import reactivemongo.api.collections.GenericCollection
    
    def createIfNotExists(coll: GenericCollection[_])(
      implicit ec: ExecutionContext): Future[Unit] =
      coll.create(failsIfExists = true)
    failsIfExists

    if true fails if the collection already exists (default: false)

    writeConcern

    the writer concern to be used

    Definition Classes
    CollectionMetaCommands
  15. final def create()(implicit ec: ExecutionContext): Future[Unit]

    Creates this collection.

    Creates this collection.

    The returned future will be completed, with an error if this collection already exists.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.collections.GenericCollection
    import reactivemongo.api.commands.CommandException
    
    def createColl(
      coll: GenericCollection[_])(implicit ec: ExecutionContext) =
      coll.create().recover {
        case CommandException.Code(48) => // NamespaceExists
          println(s"Collection \${coll} already exists")
      }
    Definition Classes
    CollectionMetaCommands
  16. final def createCapped(size: Long, maxDocuments: Option[Int])(implicit ec: ExecutionContext): Future[Unit]

    Creates this collection as a capped one.

    Creates this collection as a capped one.

    The returned future will be completed with an error if this collection already exists.

    import scala.concurrent.{ ExecutionContext, Future }
    
    def capped(coll: reactivemongo.api.bson.collection.BSONCollection)(
      implicit ec: ExecutionContext): Future[Unit] =
      coll.createCapped(size = 10, maxDocuments = Some(100))
    size

    the size of the collection (number of bytes)

    maxDocuments

    the maximum number of documents this capped collection can contain

    Definition Classes
    CollectionMetaCommands
    See also

    convertToCapped

  17. def createView(name: String, operator: PipelineOperator, pipeline: Seq[PipelineOperator], collation: Option[Collation] = None)(implicit ec: ExecutionContext): Future[Unit]

    Creates a view on this collection, using an aggregation pipeline.

    Creates a view on this collection, using an aggregation pipeline.

    name

    the name of the view to be created

    operator

    the first (required) operator for the aggregation pipeline

    pipeline

    the other pipeline operators

    collation

    the view collation

    Definition Classes
    GenericCollectionMetaCommands
    Since

    MongoDB 3.4

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.{ BSONDocument, BSONString }
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection)(implicit ec: ExecutionContext) = {
      import coll.AggregationFramework
      import AggregationFramework.{ Group, Match, SumField }
    
      // See http://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/#return-states-with-populations-above-10-million
    
      // Create 'myview'
      coll.createView(
        name = "myview",
        operator = Group(BSONString(f"$$state"))(
          "totalPop" -> SumField("population")),
        pipeline = Seq(Match(
          BSONDocument("totalPop" -> BSONDocument(f"$$gte" -> 10000000L)))))
    
      // Then the view can be resolved as any collection
      // (but won't be writeable)
      coll.db[BSONCollection]("myview")
    }
  18. def defaultCursorBatchSize: Int
    Attributes
    protected
    Annotations
    @inline()
  19. def delete(ordered: Boolean = true, writeConcern: WriteConcern = writeConcern): DeleteBuilder

    Prepares a delete builder.

    Prepares a delete builder.

    ordered

    the ordered behaviour

    writeConcern

    the writer concern to be used

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection, query: BSONDocument)(
      implicit ec: ExecutionContext) = coll.delete(true).one(query)
  20. def delete: DeleteBuilder

    Prepares an unordered delete builder.

    Prepares an unordered delete builder.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def doIt(coll: BSONCollection, query: BSONDocument)(
      implicit ec: ExecutionContext) = coll.delete.one(query)
    
    def equivalentTo(coll: BSONCollection) = coll.delete(false)
  21. final def deleteWriter(session: Option[Session]): P.Writer[DeleteCmd]
    Attributes
    protected
    Definition Classes
    DeleteCommand
  22. implicit final lazy val deleteWriter: P.Writer[DeleteCmd]
    Attributes
    protected
    Definition Classes
    DeleteCommand
  23. def distinct[T, M[_] <: Iterable[_]](key: String, selector: Option[P.Document] = None, readConcern: ReadConcern = self.readConcern, collation: Option[Collation] = None)(implicit reader: P.NarrowValueReader[T], ec: ExecutionContext, cbf: Factory[T, M[T]]): Future[M[T]]

    Returns the distinct values for a specified field across a single collection.

    Returns the distinct values for a specified field across a single collection.

    T

    the element type of the distinct values

    M

    the container, that must be a scala.collection.Iterable

    key

    the field for which to return distinct values

    selector

    the document selector, that specifies the documents from which to retrieve the distinct values.

    readConcern

    the read concern

    collation

    the collation

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.ReadConcern
    import reactivemongo.api.bson.collection.BSONCollection
    
    def distinctStates(coll: BSONCollection)(implicit ec: ExecutionContext) =
      coll.distinct[String, Set]("state", None, ReadConcern.Local, None)
    Definition Classes
    GenericCollectionWithDistinctOps
  24. def distinctDocuments[T, M[_] <: Iterable[_]](key: String, query: Option[P.Document], readConcern: ReadConcern, collation: Option[Collation], builder: Builder[T, M[T]])(implicit reader: P.NarrowValueReader[T], ec: ExecutionContext): Future[M[T]]
    Attributes
    protected
    Definition Classes
    DistinctOp
  25. final def distinctDocuments[T, M[_] <: Iterable[_]](key: String, query: Option[P.Document], readConcern: ReadConcern, collation: Option[Collation])(implicit reader: P.NarrowValueReader[T], ec: ExecutionContext, cbf: Factory[T, M[T]]): Future[M[T]]
    Attributes
    protected
    Definition Classes
    DistinctOpCompat
  26. final def drop(failIfNotFound: Boolean)(implicit ec: ExecutionContext): Future[Boolean]

    Drops this collection.

    Drops this collection.

    If the collection existed and is successfully dropped, the returned future will be completed with true.

    If failIfNotFound is false and the collection doesn't exist, the returned future will be completed with false.

    Otherwise in case, the future will be completed with the encountered error.

    import scala.concurrent.{ ExecutionContext, Future }
    import reactivemongo.api.collections.GenericCollection
    
    def dropIfNotFound(coll: GenericCollection[_])(
      implicit ec: ExecutionContext): Future[Boolean] =
      coll.drop(failIfNotFound = true)
    failIfNotFound

    the flag to request whether it should fail

    Definition Classes
    CollectionMetaCommands
  27. def drop()(implicit ec: ExecutionContext): Future[Unit]

    Drops this collection.

    Drops this collection.

    The returned future will be completed with an error if this collection does not exist.

    Definition Classes
    CollectionMetaCommands
  28. def ensuring(cond: (GenericCollection[P]) => Boolean, msg: => Any): GenericCollection[P]
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toEnsuring[GenericCollection[P]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  29. def ensuring(cond: (GenericCollection[P]) => Boolean): GenericCollection[P]
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toEnsuring[GenericCollection[P]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  30. def ensuring(cond: Boolean, msg: => Any): GenericCollection[P]
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toEnsuring[GenericCollection[P]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  31. def ensuring(cond: Boolean): GenericCollection[P]
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toEnsuring[GenericCollection[P]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  32. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  33. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  34. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  35. def find[S, J](selector: S, projection: Option[J])(implicit swriter: P.Writer[S], pwriter: P.Writer[J]): QueryBuilder

    Finds the documents matching the given criteria (selector), with the projection applied.

    Finds the documents matching the given criteria (selector), with the projection applied.

    S

    The type of the selector. An implicit Writer[S] typeclass for handling it has to be in the scope.

    selector

    the document selector

    projection

    the projection document to select only a subset of each matching documents

    swriter

    the writer for the selector

    pwriter

    the writer for the projection

    returns

    A query builder you can use to customize the query. You can obtain a cursor by calling the method reactivemongo.api.Cursor on this query builder.

    See also

    MongoDB documentation

  36. def find[S](selector: S)(implicit swriter: P.Writer[S]): QueryBuilder

    Finds the documents matching the given criteria (selector), with the projection applied.

    Finds the documents matching the given criteria (selector), with the projection applied.

    S

    The type of the selector. An implicit Writer[S] typeclass for handling it has to be in the scope.

    selector

    the document selector

    swriter

    the writer for the selector

    returns

    A query builder you can use to customize the query. You can obtain a cursor by calling the method reactivemongo.api.Cursor on this query builder.

    See also

    MongoDB documentation

  37. def findAndModify[S](selector: S, modifier: FindAndModifyOp, sort: Option[P.Document] = None, fields: Option[P.Document] = None, bypassDocumentValidation: Boolean = false, writeConcern: WriteConcern = this.writeConcern, maxTime: Option[FiniteDuration] = None, collation: Option[Collation] = None, arrayFilters: Seq[P.Document] = Seq.empty)(implicit swriter: P.Writer[S], ec: ExecutionContext): Future[FindAndModifyResult]

    Applies a findAndModify operation.

    Applies a findAndModify operation. See findAndUpdate and findAndRemove convenient functions.

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }
    import reactivemongo.api.bson.collection.BSONCollection
    
    case class Person(name: String, age: Int)
    
    def foo(coll: BSONCollection)(
      implicit ec: ExecutionContext, r: BSONDocumentReader[Person]) = {
      val updateOp = coll.updateModifier(
        BSONDocument(f"$$set" -> BSONDocument("age" -> 35)))
    
      val personBeforeUpdate: Future[Option[Person]] =
        coll.findAndModify(BSONDocument("name" -> "Joline"), updateOp).
        map(_.result[Person])
    
      val removedPerson: Future[Option[Person]] = coll.findAndModify(
        BSONDocument("name" -> "Jack"), coll.removeModifier).
        map(_.result[Person])
    
      val _ = List(personBeforeUpdate, removedPerson)
    }
    selector

    the document selector

    modifier

    the modify operator to be applied

    sort

    the document indicating the sort criteria (default: None)

    fields

    the projection fields

    bypassDocumentValidation

    the flag to bypass document validation during the operation (default: false)

    writeConcern

    the writer concern to be used

    maxTime

    the time limit for processing operations on a cursor (maxTimeMS)

    collation

    the collation

    arrayFilters

    an array of filter documents that determines which array elements to modify for an update operation on an array field

    swriter

    the writer for the selector

    Annotations
    @SuppressWarnings()
  38. def findAndRemove[S](selector: S, sort: Option[P.Document] = None, fields: Option[P.Document] = None, writeConcern: WriteConcern = this.writeConcern, maxTime: Option[FiniteDuration] = None, collation: Option[Collation] = None, arrayFilters: Seq[P.Document] = Seq.empty)(implicit swriter: P.Writer[S], ec: ExecutionContext): Future[FindAndModifyResult]

    Finds some matching document, and removes it (using findAndModify).

    Finds some matching document, and removes it (using findAndModify).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }
    import reactivemongo.api.bson.collection.BSONCollection
    
    case class Person(name: String, age: Int)
    
    def removed(coll: BSONCollection)(
      implicit ec: ExecutionContext,
      r: BSONDocumentReader[Person]): Future[Option[Person]] =
      coll.findAndRemove(
        BSONDocument("name" -> "Foo")).map(_.result[Person])
    S

    The type of the selector. An implicit Writer[S] typeclass for handling it has to be in the scope.

    selector

    the document selector

    sort

    the document indicating the sort criteria

    fields

    the projection fields

    writeConcern

    the writer concern to be used

    maxTime

    the time limit for processing operations on a cursor (maxTimeMS)

    collation

    the collation

    arrayFilters

    an array of filter documents that determines which array elements to modify for an update operation on an array field

    swriter

    the writer for the selector

  39. def findAndUpdate[S, T](selector: S, update: T, fetchNewObject: Boolean = false, upsert: Boolean = false, sort: Option[P.Document] = None, fields: Option[P.Document] = None, bypassDocumentValidation: Boolean = false, writeConcern: WriteConcern = this.writeConcern, maxTime: Option[FiniteDuration] = None, collation: Option[Collation] = None, arrayFilters: Seq[P.Document] = Seq.empty)(implicit swriter: P.Writer[S], writer: P.Writer[T], ec: ExecutionContext): Future[FindAndModifyResult]

    Finds some matching document, and updates it (using findAndModify).

    Finds some matching document, and updates it (using findAndModify).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findPerson(coll: BSONCollection)(
      implicit ec: ExecutionContext): Future[Option[BSONDocument]] =
      coll.findAndUpdate(
        BSONDocument("name" -> "James"),
        BSONDocument(f"$$set" -> BSONDocument("age" -> 17)),
        fetchNewObject = true).map(_.value)
        // on success, return the update document: { "age": 17 }
    selector

    the document selector

    update

    the update to be applied

    fetchNewObject

    the command result must be the new object instead of the old one (default: false)

    upsert

    if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied (default: false)

    sort

    the document indicating the sort criteria (default: None)

    fields

    the projection fields

    bypassDocumentValidation

    the flag to bypass document validation during the operation (default: false)

    writeConcern

    the writer concern to be used

    maxTime

    the time limit for processing operations on a cursor (maxTimeMS)

    collation

    the collation

    arrayFilters

    an array of filter documents that determines which array elements to modify for an update operation on an array field

    swriter

    the writer for the selector

    writer

    the writer to create the document

    Annotations
    @SuppressWarnings()
  40. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toStringFormat[GenericCollection[P]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  41. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  42. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  43. def hint(specification: P.Document): Hint

    Returns a hint for the given index specification document.

    Returns a hint for the given index specification document.

    specification

    the index specification document

    Definition Classes
    HintFactory
  44. def hint(name: String): Hint

    Returns a hint for the given index name.

    Returns a hint for the given index name.

    name

    the index name

    Definition Classes
    HintFactory
  45. final def indexesManager(implicit ec: ExecutionContext): Aux[Pack]

    Returns an index manager for this collection.

    Returns an index manager for this collection.

    import scala.concurrent.{ ExecutionContext, Future }
    import reactivemongo.api.collections.GenericCollection
    
    def listIndexes(coll: GenericCollection[_])(
      implicit ec: ExecutionContext): Future[List[String]] =
      coll.indexesManager.list().map(_.flatMap { idx =>
        idx.name.toList
      })
    Definition Classes
    CollectionMetaCommands
  46. def insert(ordered: Boolean, writeConcern: WriteConcern, bypassDocumentValidation: Boolean): InsertBuilder

    Returns a builder for insert operations.

    Returns a builder for insert operations.

    ordered

    the ordered behaviour

    writeConcern

    the writer concern to be used

    bypassDocumentValidation

    the flag to bypass document validation during the operation

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(coll: BSONCollection, query: BSONDocument)(
      implicit ec: ExecutionContext) =
      coll.insert(true, WriteConcern.Journaled, true).one(query)
  47. def insert(ordered: Boolean, bypassDocumentValidation: Boolean): InsertBuilder

    Returns a builder for insert operations.

    Returns a builder for insert operations. Uses the default write concern.

    ordered

    the ordered behaviour

    bypassDocumentValidation

    the flag to bypass document validation during the operation

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(coll: BSONCollection, query: BSONDocument)(
      implicit ec: ExecutionContext) =
      coll.insert(true, false).one(query)
  48. def insert(ordered: Boolean, writeConcern: WriteConcern): InsertBuilder

    Returns a builder for insert operations.

    Returns a builder for insert operations.

    ordered

    the ordered behaviour

    writeConcern

    the writer concern to be used

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(coll: BSONCollection, query: BSONDocument)(
      implicit ec: ExecutionContext) =
      coll.insert(true, WriteConcern.Journaled).one(query)
  49. def insert(writeConcern: WriteConcern): InsertBuilder

    Returns an ordered builder for insert operations.

    Returns an ordered builder for insert operations.

    writeConcern

    the writer concern to be used

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def one(coll: BSONCollection, singleDoc: BSONDocument)(
      implicit ec: ExecutionContext) =
      coll.insert(writeConcern = WriteConcern.Default).one(singleDoc)
    
    def many(coll: BSONCollection, multiInserts: Iterable[BSONDocument])(
      implicit ec: ExecutionContext) =
      coll.insert(writeConcern = WriteConcern.Default).many(multiInserts)
  50. def insert(ordered: Boolean): InsertBuilder

    Returns a builder for insert operations.

    Returns a builder for insert operations. Uses the default write concern.

    ordered

    the ordered behaviour

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def one(coll: BSONCollection, singleDoc: BSONDocument)(
      implicit ec: ExecutionContext) =
      coll.insert(ordered = true).one(singleDoc)
    
    def many(coll: BSONCollection, multiInserts: Iterable[BSONDocument])(
      implicit ec: ExecutionContext) =
      coll.insert(ordered = true).many(multiInserts)
  51. def insert: InsertBuilder

    Returns an unordered builder for insert operations.

    Returns an unordered builder for insert operations. Uses the default write concern.

  52. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  53. lazy val maxWireVersion: MongoWireVersion
    Attributes
    protected
    Definition Classes
    UpdateOps → UpdateCommand
  54. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  55. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  56. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  57. def readConcern: ReadConcern

    The default read concern

    The default read concern

    Attributes
    protected
    Annotations
    @inline()
  58. def removeModifier: FindAndRemoveOp

    Returns a removal modifier, to be used with findAndModify.

    Returns a removal modifier, to be used with findAndModify.

    Annotations
    @inline()
  59. implicit final lazy val resultReader: P.Reader[DefaultWriteResult]
    Attributes
    protected
    Definition Classes
    CommandCodecsWithPack
  60. def runCommand[C <: CollectionCommand](command: C)(implicit writer: P.Writer[ResolvedCollectionCommand[C]]): CursorFetcher[pack.type, Cursor]
    Definition Classes
    GenericCollectionWithCommands
  61. def runCommand[R, C <: CollectionCommand with CommandWithResult[R]](command: C with CommandWithResult[R], readPreference: ReadPreference = self.readPreference)(implicit writer: P.Writer[ResolvedCollectionCommand[C]], reader: P.Reader[R], ec: ExecutionContext): Future[R]
    Definition Classes
    GenericCollectionWithCommands
  62. def runWithResponse[R, C <: CollectionCommand with CommandWithResult[R]](command: C with CommandWithResult[R], readPreference: ReadPreference = self.readPreference)(implicit writer: P.Writer[ResolvedCollectionCommand[C]], reader: P.Reader[R], ec: ExecutionContext): Future[ResponseResult[R]]
    Definition Classes
    GenericCollectionWithCommands
  63. def runner: CommandWithPackRunner[pack.type]

    The command runner

    The command runner

    Definition Classes
    GenericCollectionWithCommands
  64. final def stats(scale: Int)(implicit ec: ExecutionContext): Future[CollectionStats]

    Returns various information about this collection.

    Returns various information about this collection.

    import scala.concurrent.{ ExecutionContext, Future }
    
    def getSize(coll: reactivemongo.api.bson.collection.BSONCollection)(
      implicit ec: ExecutionContext): Future[Double] =
      coll.stats(scale = 1024).map(_.size)
    scale

    the scale factor (for example, to get all the sizes in kilobytes)

    Definition Classes
    CollectionMetaCommands
  65. final def stats()(implicit ec: ExecutionContext): Future[CollectionStats]

    Returns various information about this collection.

    Returns various information about this collection.

    import scala.concurrent.{ ExecutionContext, Future }
    
    def isCapped(coll: reactivemongo.api.bson.collection.BSONCollection)(
      implicit ec: ExecutionContext): Future[Boolean] =
      coll.stats().map(_.capped)
    Definition Classes
    CollectionMetaCommands
  66. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  67. def toString(): String
    Definition Classes
    GenericCollection → AnyRef → Any
  68. implicit lazy val unitReader: P.Reader[Unit]
    Attributes
    protected
  69. def unsupportedVersion(metadata: ProtocolMetadata): GenericDriverException
    Attributes
    protected
    Annotations
    @inline()
  70. def update(ordered: Boolean, writeConcern: WriteConcern, bypassDocumentValidation: Boolean): UpdateBuilder

    Returns an update builder.

    Returns an update builder.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def myUpdate(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument,
      wc: WriteConcern
    )(implicit ec: ExecutionContext) = coll.update(
      ordered = false,
      writeConcern = wc,
      bypassDocumentValidation = true
    ).one(query, update)
    ordered

    the ordered behaviour

    writeConcern

    the writer concern to be used

    bypassDocumentValidation

    the flag to bypass document validation during the operation

  71. def update(ordered: Boolean, bypassDocumentValidation: Boolean): UpdateBuilder

    Returns an update builder.

    Returns an update builder. Uses the default write concern.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument
    )(implicit ec: ExecutionContext) = coll.update(
      ordered = false,
      bypassDocumentValidation = true
    ).one(query, update)
    ordered

    the ordered behaviour

    bypassDocumentValidation

    the flag to bypass document validation during the operation

  72. def update(ordered: Boolean, writeConcern: WriteConcern): UpdateBuilder

    Returns an update builder.

    Returns an update builder.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def myUpdate(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument,
      wc: WriteConcern
    )(implicit ec: ExecutionContext) =
      coll.update(ordered = false, writeConcern = wc).one(query, update)
    ordered

    the ordered behaviour

    writeConcern

    the writer concern to be used

  73. def update(writeConcern: WriteConcern): UpdateBuilder

    Returns an ordered update builder.

    Returns an ordered update builder.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.WriteConcern
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def orderedUpdate(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument,
      wc: WriteConcern
    )(implicit ec: ExecutionContext) =
      coll.update(writeConcern = wc).one(query, update)
    writeConcern

    the writer concern to be used

  74. def update(ordered: Boolean): UpdateBuilder

    Returns an update builder.

    Returns an update builder. Uses the default write concern.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument
    )(implicit ec: ExecutionContext) = {
      coll.update(ordered = true).
        one(query, update, upsert = false, multi = false)
    }
    ordered

    the ordered behaviour

  75. def update: UpdateBuilder

    Returns an unordered update builder.

    Returns an unordered update builder. Uses the default write concern.

    import scala.concurrent.ExecutionContext
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def withDefaultWriteConcern(
      coll: BSONCollection,
      query: BSONDocument,
      update: BSONDocument
    )(implicit ec: ExecutionContext) = {
      coll.update.one(query, update, upsert = false, multi = false)
    }
  76. def updateModifier[U](update: U, fetchNewObject: Boolean = false, upsert: Boolean = false)(implicit updateWriter: P.Writer[U]): FindAndUpdateOp

    Returns an update modifier, to be used with findAndModify.

    Returns an update modifier, to be used with findAndModify.

    update

    the update to be applied

    fetchNewObject

    the command result must be the new object instead of the old one.

    upsert

    if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied

  77. implicit final def updateReader: P.Reader[UpdateWriteResult]
    Attributes
    protected
    Definition Classes
    UpdateCommand
  78. lazy val version: MongoWireVersion

    Upper MongoDB version (used for version checks)

    Upper MongoDB version (used for version checks)

    Attributes
    protected
  79. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  80. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  81. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  82. final def watch[T](offset: Option[Offset] = None, pipeline: List[PipelineOperator] = Nil, maxTime: Option[FiniteDuration] = None, fullDocumentStrategy: Option[FullDocumentStrategy] = None)(implicit reader: P.Reader[T]): WatchBuilder[T]

    EXPERIMENTAL: Prepares a builder for watching the change stream of this collection.

    EXPERIMENTAL: Prepares a builder for watching the change stream of this collection.

    Note: The target mongo instance MUST be a replica-set (even in the case of a single node deployement).

    import reactivemongo.api.Cursor
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def events(coll: BSONCollection): Cursor[BSONDocument] =
      coll.watch[BSONDocument]().cursor
    T

    the type into which Change Events are deserialized

    offset

    the change stream offset

    pipeline

    The sequence of aggregation stages to apply on events in the stream (see MongoDB documentation for a list of valid stages for a change stream).

    fullDocumentStrategy

    if set to UpdateLookup, every update change event will be joined with the current version of the relevant document.

    reader

    the reader of the resulting change events

    Definition Classes
    ChangeStreamOps
    Since

    MongoDB 3.6

  83. def watchFailure[T](future: => Future[T]): Future[T]
    Attributes
    protected
    Annotations
    @SuppressWarnings()
  84. def writeConcern: WriteConcern

    The default write concern

    The default write concern

    Attributes
    protected
    Annotations
    @inline()
  85. final def writeElement(builder: Builder[pack.type]): (UpdateElement) => P.Document
    Attributes
    protected[reactivemongo]
    Definition Classes
    UpdateCommand
  86. def writePreference: ReadPreference

    The read preference for the write operations (primary)

    The read preference for the write operations (primary)

    Attributes
    protected
    Annotations
    @inline()
  87. object FindAndRemoveOp extends (FindAndModifyCommand.this)#FindAndModifyOp

    Remove (part of a FindAndModify command).

    Remove (part of a FindAndModify command).

    Definition Classes
    FindAndModifyCommand
  88. object Upserted
    Definition Classes
    UpsertedFactory

Deprecated Value Members

  1. def [B](y: B): (GenericCollection[P], B)
    Implicit
    This member is added by an implicit conversion from GenericCollection[P] toArrowAssoc[GenericCollection[P]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from QueryBuilderFactory[P]

Inherited from HintFactory[P]

Inherited from GenericCollectionMetaCommands[P]

Inherited from AggregationOps[P]

Inherited from ChangeStreamOps[P]

Inherited from FindAndModifyOps[P]

Inherited from FindAndModifyCommand[P]

Inherited from GenericCollectionWithDistinctOps[P]

Inherited from DistinctOp[P]

Inherited from DistinctOpCompat[P]

Inherited from CountOp[P]

Inherited from DeleteOps[P]

Inherited from DeleteCommand[P]

Inherited from UpdateOps[P]

Inherited from UpdateWriteResultFactory[P]

Inherited from UpdateCommand[P]

Inherited from InsertOps[P]

Inherited from LastErrorFactory[P]

Inherited from UpsertedFactory[P]

Inherited from MultiBulkWriteResultFactory[P]

Inherited from CommandCodecsWithPack[P]

Inherited from InsertCommand[P]

Inherited from CollectionMetaCommands

Inherited from GenericCollectionWithCommands[P]

Inherited from PackSupport[P]

Inherited from Collection

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromGenericCollection[P] to any2stringadd[GenericCollection[P]]

Inherited by implicit conversion StringFormat fromGenericCollection[P] to StringFormat[GenericCollection[P]]

Inherited by implicit conversion Ensuring fromGenericCollection[P] to Ensuring[GenericCollection[P]]

Inherited by implicit conversion ArrowAssoc fromGenericCollection[P] to ArrowAssoc[GenericCollection[P]]

Ungrouped