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.
reactivemongo.api.commands.AggregationFramework.PipelineOperator
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.
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.
The database which this collection belong to.
The database which this collection belong to.
The name of the collection.
The name of the collection.
Returns a new reference to the same collection, with the given read preference.
The default failover strategy for the methods of this collection.
The default failover strategy for the methods of this collection.
(Since version 0.16.0) Internal: will be made private
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
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 writer concern to be used
the batch size (for the aggregation cursor; if None
use the default one)
the options for the result cursor
specifies a time limit in milliseconds for processing operations on a cursor.
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 document selector
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; see hint(..)
)
the read concern
if true fails if the collection already exists (default: false)
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
Prepares a delete builder.
Prepares a delete builder.
the ordered behaviour
the writer concern to be used
collection.delete(true, defaultWriteConcern).one(document, limit)
Prepares an unordered delete builder.
Prepares an unordered delete builder.
collection.delete.one(document, limit)
// Equivalent to .delete(false, defaultWriteConcern)
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
the collation
val distinctStates = collection.distinct[String, Set]( "state", None, ReadConcern.Local, None)
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.
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 collation
an array of filter documents that determines which array elements to modify for an update operation on an array field
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 concern to be used
the collation
an array of filter documents that determines which array elements to modify for an update operation on an array field
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 concern to be used
the collation
an array of filter documents that determines which array elements to modify for an update operation on an array field
the writer for the selector
the writer to create the document
Returns a hint for the given index specification
document.
Returns a hint for the given index specification
document.
the index specification document
Returns a hint for the given index name
.
Returns a hint for the given index name
.
the index name
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 ordered behaviour
the writer concern to be used
collection.insert(true, aWriteConcern).one(singleDoc) collection.insert(true, aWriteConcern).many(multiInserts)
Returns a builder for insert operations.
Returns a builder for insert operations. Uses the default write concern.
the ordered behaviour
collection.insert(ordered = true).one(singleDoc) collection.insert(ordered = true).many(multiInserts)
Returns an unordered builder for insert operations.
Returns an unordered builder for insert operations. Uses the default write concern.
The default read concern
The default read concern
The default read preference
The default read preference
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.
collection.update(ordered = true). one(query, update, upsert = false, multi = false)
Returns an unordered update builder.
Returns an unordered update builder.
collection.update.one(query, update, upsert = false, multi = false)
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
Upper MongoDB version (used for version checks)
Upper MongoDB version (used for version checks)
Prepares a builder for watching the changeStream of this collection https://docs.mongodb.com/manual/changeStreams (since MongoDB 3.6).
Prepares a builder for watching the changeStream of this collection https://docs.mongodb.com/manual/changeStreams (since MongoDB 3.6).
Note: the target mongo instance MUST be a replica-set (even in the case of a single node deployement).
the type into which Change Events are deserialized
The id of the last known Change Event, if any. The stream will resume just after that event.
The operation time before which all Change Events are known. Must be in the time range of the oplog. (since MongoDB 4.0)
A sequence of aggregation stages to apply on events in the stream (see MongoDB documentation for a list of valid stages for a change stream).
The maximum amount of time in milliseconds the server waits for new data changes before returning an empty batch. In practice, this parameter controls the duration of the long-polling behavior of the cursor.
if set to UpdateLookup, every update change event will be joined with the *current* version of the relevant document.
a reader of the resulting Change Events
The default write concern
The default write concern
The read preference for the write operations (primary)
The read preference for the write operations (primary)
(Since version 0.19.0) Internal: will be private
(Since version 0.16.0) Internal: will be made private
(Since version 0.16.0) Internal: will be made private
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.16.0) Use aggregateWith
(Since version 0.17.0) Use aggregator context with optional writeConcern
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
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)
(Since version 0.16.0) Use count
with readConcern
parameter
(Since version 0.16.0) Use distinct
with Collation
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)
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.
(Since version 0.16.0) Use find
with optional projection
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.
(Since version 0.16.0) Use find
with optional projection
(Since version 0.14.0) Use other findAndModify
(Since version 0.18.0) Use the other findAndRemove
(Since version 0.18.0) Use other findAndUpdate
Gets the full qualified name of this collection.
Gets the full qualified name of this collection.
(Since version 0.17.0) Internal: will be made private
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(true, defaultWriteConcern).one(document)
(Since version 0.16.1) Use .insert(ordered = false).one(..)
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(true, defaultWriteConcern).one(document, limit)
(Since version 0.13.1) Use delete().one(selector, limit)
Returns a removal modifier, to be used with findAndModify
.
Returns a removal modifier, to be used with findAndModify
.
(Since version 0.16.0) Internal: will be made private
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.
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
(Since version 0.16.1) Use .update(ordered = false).one(..)
A Collection that provides default methods using a
SerializationPack
.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