Alias for type of the aggregation framework, depending on the type of the collection.
Alias for type of the aggregation framework, depending on the type of the collection.
Builder for delete operations.
Builder for delete operations.
Builder for insert operations.
Builder for insert operations.
Alias for reactivemongo.api.commands.AggregationFramework.PipelineOperator
Builder for update operations.
Builder for update operations.
(Since version 0.12.7) Unused
(Since version 0.12.7) Unused
The database which this collection belong to.
The database which this collection belong to.
The default failover strategy for the methods of this collection.
The default failover strategy for the methods of this collection.
The name of the collection.
The name of the collection.
Returns a new reference to the same collection, with the given read preference.
Aggregates the matching documents.
Aggregates the matching documents.
The type of the result elements. An implicit Reader[T]
typeclass for handling it has to be in the scope.
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
the read preference for the result (default: primary)
the batch size (for the aggregation cursor; if None
use the default one)
the function to create the aggregation pipeline using the aggregation framework depending on the collection type
the result reader
the cursor flattener (by default use the builtin one)
Aggregates the matching documents.
Aggregates the matching documents.
import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global import reactivemongo.bson._ import reactivemongo.api.collections.bson.BSONCollection def populatedStates(cities: BSONCollection): Future[List[BSONDocument]] = { import cities.BatchCommands.AggregationFramework import AggregationFramework.{ Group, Match, SumField } cities.aggregatorContext[BSONDocument](Group(BSONString("$state"))( "totalPop" -> SumField("population")), List( Match(document("totalPop" -> document("$gte" -> 10000000L))))). prepared.cursor.collect[List]() }
The type of the result elements. An implicit Reader[T]
typeclass for handling it has to be in the scope.
the first aggregation operator of the pipeline
the sequence of MongoDB aggregation operations
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
the read preference for the result
the result reader
Converts this collection to a capped one.
Converts this collection to a capped one.
the size of the collection (number of bytes)
the maximum number of documents this capped collection can contain
Counts the matching documents.
Counts the matching documents.
The type of hint. An implicit H => Hint
conversion has to be in the scope.
the document selector (default: None
to count all)
the maximum number of matching documents to count
the number of matching documents to skip before counting
the index to use (either the index name or the index document)
Creates this collection.
Creates this collection.
The returned future will be completed with an error if this collection already exists.
coll.create().recover { case CommandError.Code(48 /*NamespaceExists*/ ) => println(s"Collection ${coll.fullCollectionName} already exists") }
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.
the size of the collection (number of bytes)
the maximum number of documents this capped collection can contain
If true should automatically add an index on the _id
field. By default, regular collections will have an indexed _id
field, in contrast to capped collections. This MongoDB option is deprecated and will be removed in a future release.
Creates a view on this collection, using an aggregation pipeline.
Creates a view on this collection, using an aggregation pipeline.
import coll.BatchCommands.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(document("totalPop" -> document(f"$$gte" -> 10000000L))))) // Then the view can be resolved as any collection // (but won't be writeable) val view: BSONCollection = db("myview")
the name of the view to be created
the first (required) operator for the aggregation pipeline
the other pipeline operators
the view collation
Deletes the matching document(s).
Deletes the matching document(s).
the ordered behaviour
the writer concern to be used
Returns the distinct values for a specified field across a single collection.
Returns the distinct values for a specified field across a single collection.
the element type of the distinct values
the container, that must be a scala.collection.Iterable
the field for which to return distinct values
the document selector, that specifies the documents from which to retrieve the distinct values.
the read concern
val distinctStates = collection.distinct[String, Set]("state")
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.
Finds the documents matching the given criteria (selector), with the projection applied.
Finds the documents matching the given criteria (selector), with the projection applied.
The type of the selector. An implicit Writer[S]
typeclass for handling it has to be in the scope.
the document selector
the projection document to select only a subset of each matching documents
the writer for the selector
the writer for the projection
A GenericQueryBuilder that you can use to to customize the query. You can obtain a cursor by calling the method reactivemongo.api.Cursor on this query builder.
Finds the documents matching the given criteria (selector).
Finds the documents matching the given criteria (selector).
The type of the selector. An implicit Writer[S]
typeclass for handling it has to be in the scope.
the document selector
the writer for the selector
A GenericQueryBuilder that you can use to to customize the query. You can obtain a cursor by calling the method reactivemongo.api.Cursor on this query builder.
Applies a findAndModify operation.
Applies a findAndModify operation. See findAndUpdate and findAndRemove convenient functions.
val updateOp = collection.updateModifier( BSONDocument("$set" -> BSONDocument("age" -> 35))) val personBeforeUpdate: Future[Option[Person]] = collection.findAndModify(BSONDocument("name" -> "Joline"), updateOp). map(_.result[Person]) val removedPerson: Future[Option[Person]] = collection.findAndModify( BSONDocument("name" -> "Jack"), collection.removeModifier). map(_.result[Person])
the document selector
the modify operator to be applied
the document indicating the sort criteria (default: None
)
the projection fields
the writer concern to be used
the writer for the selector
Finds some matching document, and removes it (using findAndModify).
Finds some matching document, and removes it (using findAndModify).
val removed: Future[Person] = collection.findAndRemove( BSONDocument("name" -> "Foo")).map(_.result[Person])
The type of the selector. An implicit Writer[S]
typeclass for handling it has to be in the scope.
the document selector
the document indicating the sort criteria
the projection fields
the writer for the selector
Finds some matching document, and updates it (using findAndModify).
Finds some matching document, and updates it (using findAndModify).
val person: Future[BSONDocument] = collection.findAndUpdate( BSONDocument("name" -> "James"), BSONDocument("$set" -> BSONDocument("age" -> 17)), fetchNewObject = true) // on success, return the update document: // { "age": 17 }
the document selector
the update to be applied
the command result must be the new object instead of the old one.
if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied
the document indicating the sort criteria (default: None
)
the projection fields
the writer for the selector
writerParam
Gets the full qualified name of this collection.
Gets the full qualified name of this collection.
Returns an index manager for this collection.
Returns an index manager for this collection.
Returns a builder for insert operations.
Returns a builder for insert operations.
The type of the document to insert. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the ordered behaviour
the writer concern to be used
collection.insert[MyDocType](true, aWriteConcern).one(singleDoc) collection.insert[MyDocType](true, aWriteConcern).one(multiDocs)
Returns a builder for insert operations.
Returns a builder for insert operations. Uses the default write concern.
The type of the document to insert. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the ordered behaviour
collection.insert[MyDocType](ordered = true).one(singleDoc) collection.insert[MyDocType](ordered = true).one(multiDocs)
Inserts a document into the collection and waits for the reactivemongo.api.commands.WriteResult.
Inserts a document into the collection and waits for the reactivemongo.api.commands.WriteResult.
The type of the document to insert. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the document to insert
the writer concern to be used
the writer to create the document to be inserted
a future reactivemongo.api.commands.WriteResult that can be used to check whether the insertion was successful
collection.insert(myDoc) // Equivalent to: collection.insert[MyDocType](true, defaultWriteConcern).one(document)
The default read preference
Returns a removal modifier, to be used with findAndModify.
Gets another collection in the current database.
Gets another collection in the current database. An implicit CollectionProducer[C] must be present in the scope, or it will be the default implementation (reactivemongo.api.collections.bson.BSONCollection).
the name of another collection
the failover strategy to override the default one
Returns various information about this collection.
Returns various information about this collection.
the scale factor (for example, to get all the sizes in kilobytes)
Returns various information about this collection.
Returns various information about this collection.
Returns an update builder.
Returns an update builder.
collection.update(ordered, writeConcern).many(updates)
Returns an update builder.
Returns an update builder.
// Equivalent to collection.update(query, update, ...) collection.update(ordered = true). one(query, update, upsert = false, multi = false)
Updates one or more documents matching the given selector with the given modifier or update object.
Updates one or more documents matching the given selector with the given modifier or update object.
The type of the selector. An implicit Writer[S]
typeclass for handling it has to be in the scope.
The type of the modifier or update object. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the selector object, for finding the documents to update.
the modifier object (with special keys like $set) or replacement object.
the writer concern to be used
if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied (defaults: false
)
states whether the update may be done on all the matching documents (default: false
)
the writer for the selector
the writer to create the document
a future reactivemongo.api.commands.WriteResult that can be used to check whether the insertion was successful
Returns an update modifier, to be used with findAndModify.
Returns an update modifier, to be used with findAndModify.
the update to be applied
the command result must be the new object instead of the old one.
if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied
(Since version 0.12.7) Unused
Aggregates the matching documents.
Aggregates the matching documents.
The type of the result elements. An implicit Reader[T]
typeclass for handling it has to be in the scope.
the first aggregation operator of the pipeline
the sequence of MongoDB aggregation operations
aggregation cursor option (optional)
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
the read preference for the result
the result reader
the cursor flattener (by default use the builtin one)
(Since version 0.12.3) Use aggregatorContext
Aggregates the matching documents.
Aggregates the matching documents.
the first aggregation operator of the pipeline
the sequence of MongoDB aggregation operations
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
(Since version 0.12.7) Use aggregateWith1
Aggregates the matching documents.
Aggregates the matching documents.
The type of the result elements. An implicit Reader[T]
typeclass for handling it has to be in the scope.
the first aggregation operator of the pipeline
the sequence of MongoDB aggregation operations
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
the read preference for the result
the batch size (for the aggregation cursor; if None
use the default one)
the result reader
the cursor flattener (by default use the builtin one)
(Since version 0.12.3) Use aggregatorContext
Aggregates the matching documents.
Aggregates the matching documents.
The type of the result elements. An implicit Reader[T]
typeclass for handling it has to be in the scope.
if true indicates to return the information on the processing of the pipeline
if true enables writing to temporary files
if true enables to bypass document validation during the operation
the read concern
the read preference for the result (default: primary)
the batch size (for the aggregation cursor; if None
use the default one)
the function to create the aggregation pipeline using the aggregation framework depending on the collection type
the result reader
the cursor flattener (by default use the builtin one)
(Since version 0.12.3) Use aggregateWith1
Gets another implementation of this collection.
Gets another implementation of this collection. An implicit CollectionProducer[C] must be present in the scope, or it will be the default implementation (reactivemongo.api.collections.bson.BSONCollection).
the failover strategy to override the default one
(Since version 0.13.0) Resolve the collection from DB
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered).many(documents, writeConcern)
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered).many(documents, writeConcern)
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered).many(documents)
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered, writeConcern).many(documents)
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered, writeConcern).many(documents)
the ordered behaviour
(Since version 0.12.7) Use insert[T](ordered).many(documents)
DEPRECATED: If true should automatically add an index on the _id
field. By default, regular collections will have an indexed _id
field, in contrast to capped collections. This MongoDB option is deprecated and will be removed in a future release.
(Since version 0.14.0) Use create
without deprecated autoIndexId
Drops this collection.
Drops this collection.
The returned future will be completed with an error if this collection does not exist.
(Since version 0.12.0) Use drop(Boolean)
If this collection is capped, removes all the documents it contains.
If this collection is capped, removes all the documents it contains.
Deprecated because it became an internal command, unavailable by default.
(Since version 0.9) Deprecated because emptyCapped became an internal command, unavailable by default.
(Since version 0.14.0) Use other findAndModify
The type of the selector. An implicit Writer[S]
typeclass for handling it has to be in the scope.
the writer concern to be used
the writer for the selector
a future reactivemongo.api.commands.WriteResult that can be used to check whether the removal was successful
// Equivalent to: collection.delete[MyDocType](true, defaultWriteConcern).one(document, limit)
(Since version 0.13.1) Use delete().one(selector, limit)
Renames this collection.
Renames this collection.
the new name of this collection
if a collection of name to
already exists, then drops that collection before renaming this one
a failure if the dropExisting option is false and the target collection already exists
(Since version 0.12.4) Use reactivemongo.api.DBMetaCommands.renameCollection on the admin database instead.
(Since version 0.12-RC5) Use the alternative with ReadPreference
(Since version 0.12-RC5) Use the alternative with ReadPreference
(Since version 0.12-RC5) Use the alternative with ReadPreference
Inserts a document into the collection without writeConcern.
Inserts a document into the collection without writeConcern.
Please note that you cannot be sure that the document has been effectively written and when (hence the Unit return type).
the type of the document to insert. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the document to insert.
(Since version 0.12.0) Use insert[T](Boolean)
Remove the matched document(s) from the collection without writeConcern.
Remove the matched document(s) from the collection without writeConcern.
Please note that you cannot be sure that the matched documents have been effectively removed and when (hence the Unit return type).
the type of the selector of documents to remove. An implicit Writer[T]
typeclass for handling it has to be in the scope.
the selector of documents to remove.
states whether only the first matched documents has to be removed from this collection.
(Since version 0.12.0) Use remove
Updates one or more documents matching the given selector with the given modifier or update object.
Updates one or more documents matching the given selector with the given modifier or update object.
Please note that you cannot be sure that the matched documents have been effectively updated and when (hence the Unit return type).
the type of the selector object. An implicit Writer[S]
typeclass for handling it has to be in the scope.
the type of the modifier or update object. An implicit Writer[U]
typeclass for handling it has to be in the scope.
the selector object, for finding the documents to update.
the modifier object (with special keys like $set) or replacement object.
states whether the update object should be inserted if no match found. Defaults to false.
states whether the update may be done on all the matching documents.
(Since version 0.12.0) Use update(Boolean)
A Collection that provides default methods using a
SerializationPack
(e.g. the default reactivemongo.api.BSONSerializationPack).Some methods of this collection accept instances of
Reader[T]
andWriter[T]
, that transform anyT
instance into a document, compatible with the selected serialization pack, and vice-versa.the serialization pack