GenericCollection
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.
Attributes
- P
the serialization pack
- Graph
- Supertypes
- trait QueryBuilderFactory[P]trait AggregationOps[P]trait ChangeStreamOps[P]trait FindAndModifyOps[P]trait FindAndModifyCommand[P]trait DeleteOps[P]trait UpdateOps[P]trait InsertOps[P]trait UpsertedFactory[P]trait MultiBulkWriteResultFactory[P]trait Collectionclass Objecttrait Matchableclass Any
- Self type
Members list
Type members
Inherited classlikes
The aggregation framework for this collection
The aggregation framework for this collection
Attributes
- Inherited from:
- AggregationOps
- Graph
- Supertypes
Aggregator context
Aggregator context
Attributes
- Inherited from:
- AggregationOps
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Builder for delete operations.
Builder for delete operations.
Attributes
- Inherited from:
- DeleteOps
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Delete command element
Delete command element
Attributes
- Inherited from:
- DeleteCommand (hidden)
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Attributes
- values
the raw values (should not contain duplicate)
- Inherited from:
- DistinctOp (hidden)
- Graph
- Supertypes
A modify operation, part of a FindAndModify command
A modify operation, part of a FindAndModify command
Attributes
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
- Known subtypes
Result for a find-and-modify command
Result for a find-and-modify command
Attributes
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Remove (part of a FindAndModify command).
Remove (part of a FindAndModify command).
Attributes
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
Last error for a find-and-update command
Last error for a find-and-update command
Attributes
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Update (part of a FindAndModify command).
Update (part of a FindAndModify command).
Attributes
- fetchNewObject
the command result must be the new object instead of the old one.
- update
the modifier document.
- upsert
if true, creates a new document if no document matches the query, or if documents match the query, findAndModify performs an update
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
Update (part of a FindAndModify command).
Update (part of a FindAndModify command).
Attributes
- fetchNewObject
the command result must be the new object instead of the old one.
- update
the aggregation pipeline
- upsert
if true, creates a new document if no document matches the query, or if documents match the query, findAndModify performs an update
- Inherited from:
- FindAndModifyCommand
- Graph
- Supertypes
An index hint
An index hint
Attributes
- Inherited from:
- HintFactory (hidden)
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Builder for insert operations.
Builder for insert operations.
Attributes
- Inherited from:
- InsertOps
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
The result of a bulk write operation.
The result of a bulk write operation.
Attributes
- Inherited from:
- MultiBulkWriteResultFactory
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
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.
Attributes
- batchSize
the upper limit on the number of documents to retrieve per batch (0 for unspecified)
- collation
the optional collation to use for the find command (default:
None
) {@since MongoDB 3.4}import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.bson.BSONDocument import reactivemongo.api.bson.collection.BSONCollection def firstFirst(coll: BSONCollection)( implicit ec: ExecutionContext): Future[Option[BSONDocument]] = { val queryBuilder = coll.find(BSONDocument.empty) queryBuilder.one[BSONDocument] }
- comment
the query comment
- cursorOptions
the cursor options
- explain
the explain flag
- filter
the query filter
- hint
the index to “hint” or force MongoDB to use when performing the query.
- max
the optional exclusive upper bound for a specific index (default:
None
)- maxScan
this option specifies a maximum number of documents or index keys the query plan will scan.
- maxTimeMs
the maximum execution time
- min
the optional exclusive lower bound for a specific index (default:
None
)- projection
- readConcern
the read concern {@since MongoDB 3.6}
- readPreference
the query ReadPreference
- returnKey
if this flag is true, returns only the index keys in the resulting documents
- showRecordId
the flags to determines whether to return the record identifier for each document
- singleBatch
the flag to determines whether to close the cursor after the first batch (default:
false
)- skip
the number of documents to skip.
- snapshot
the snapshot flag
- sort
the optional sort specification
- Inherited from:
- QueryBuilderFactory
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Builder for update operations.
Builder for update operations.
Attributes
- Inherited from:
- UpdateOps
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Attributes
- arrayFilters
an array of filter documents that determines which array elements to modify for an update operation on an array field
- collation
the collation to use for the operation
- multi
if true updates all the matching documents
- q
the query that matches the documents to update
- u
the modifications to apply
- upsert
if true perform an insert if no documents match the query
- Inherited from:
- UpdateCommand (hidden)
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Result for the update operations.
Result for the update operations.
Attributes
- n
the number of documents selected for update
- nModified
the number of updated documents
- ok
the update status
- upserted
the upserted documents
- Inherited from:
- UpdateWriteResultFactory (hidden)
- Graph
- Supertypes
An upserted element
An upserted element
Attributes
- Inherited from:
- UpsertedFactory
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Attributes
- Inherited from:
- UpsertedFactory
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
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.
Attributes
- Inherited from:
- ChangeStreamOps
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
Inherited types
Aggregation framework
Result for a delete command
Result for a delete command
Attributes
- Inherited from:
- DeleteCommand (hidden)
Aggregation pipeline operator/stage
Value members
Abstract methods
The default read preference
The default read preference
Attributes
Returns a new reference to the same collection, with the given read preference.
Returns a new reference to the same collection, with the given read preference.
Attributes
Concrete methods
Aggregates the matching documents.
Aggregates the matching documents.
Attributes
- T
The type of the result elements. An implicit
Reader[T]
typeclass for handling it has to be in the scope.- allowDiskUse
if true enables writing to temporary files
- batchSize
the batch size (for the aggregation cursor; if
None
use the default one)- bypassDocumentValidation
the flag to bypass document validation during the operation (default:
false
)- explain
if true indicates to return the information on the processing of the pipeline
- f
the function to create the aggregation pipeline using the aggregation framework depending on the collection type
- readConcern
the read concern
- readPreference
the read preference for the result (default: primary)
- reader
the result reader
'''EXPERIMENTAL:'''
Returns an update modifier, to be used with findAndModify
.
'''EXPERIMENTAL:'''
Returns an update modifier, to be used with findAndModify
.
Attributes
- fetchNewObject
the command result must be the new object instead of the old one
- update
the aggregation pipeline
- upsert
if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied
Counts the matching documents.
Counts the matching documents.
Attributes
- hint
the index to use (either the index name or the index document; see
hint(..)
)- limit
the maximum number of matching documents to count
- readConcern
the read concern
- readPreference
the read preference for the result
- selector
the document selector
- skip
the number of matching documents to skip before counting
- See also:
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)
Attributes
Prepares a delete builder.
Prepares a delete builder.
Attributes
- 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)
Finds the documents matching the given criteria (selector), with the projection applied.
Finds the documents matching the given criteria (selector), with the projection applied.
Attributes
- P
The type of the projection object. An implicit
Writer[P]
typeclass for handling it has to be in the scope.- S
The type of the selector. An implicit
Writer[S]
typeclass for handling it has to be in the scope.- pwriter
the writer for the projection
- 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:
Finds the documents matching the given criteria (selector), with the projection applied.
Finds the documents matching the given criteria (selector), with the projection applied.
Attributes
- P
The type of the projection object. An implicit
Writer[P]
typeclass for handling it has to be in the scope.- S
The type of the selector. An implicit
Writer[S]
typeclass for handling it has to be in the scope.- projection
the projection document to select only a subset of each matching documents
- pwriter
the writer for the projection
- 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:
Applies a findAndModify operation. See findAndUpdate
and findAndRemove
convenient functions.
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)
}
Attributes
- arrayFilters
an array of filter documents that determines which array elements to modify for an update operation on an array field
- bypassDocumentValidation
the flag to bypass document validation during the operation (default:
false
)- collation
the collation
- fields
the projection fields
- maxTime
the time limit for processing operations on a cursor (
maxTimeMS
)- modifier
the modify operator to be applied
- selector
the document selector
- sort
the document indicating the sort criteria (default:
None
)- swriter
the writer for the selector
- tparam
S The type of the selector. An implicit
Writer[S]
typeclass for handling it has to be in the scope.- writeConcern
the writer concern to be used
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])
Attributes
- S
The type of the selector. An implicit
Writer[S]
typeclass for handling it has to be in the scope.- arrayFilters
an array of filter documents that determines which array elements to modify for an update operation on an array field
- collation
the collation
- fields
the projection fields
- maxTime
the time limit for processing operations on a cursor (
maxTimeMS
)- modifier
the modify operator to be applied
- selector
the document selector
- sort
the document indicating the sort criteria
- swriter
the writer for the selector
- writeConcern
the writer concern to be used
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 }
Attributes
- arrayFilters
an array of filter documents that determines which array elements to modify for an update operation on an array field
- bypassDocumentValidation
the flag to bypass document validation during the operation (default:
false
)- collation
the collation
- fetchNewObject
the command result must be the new object instead of the old one (default:
false
)- fields
the projection fields
- maxTime
the time limit for processing operations on a cursor (
maxTimeMS
)- selector
the document selector
- sort
the document indicating the sort criteria (default:
None
)- swriter
the writer for the selector
- update
the update to be applied
- 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
)- writeConcern
the writer concern to be used
- writer
the writer to create the document
'''EXPERIMENTAL:'''
Finds some matching document, and updates it (using findAndModify
).
'''EXPERIMENTAL:'''
Finds some matching document, and updates it (using findAndModify
).
import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.api.bson.{ BSONArray, BSONDocument }
import reactivemongo.api.bson.collection.BSONCollection
def findPerson(coll: BSONCollection)(
implicit ec: ExecutionContext): Future[Option[BSONDocument]] = {
import coll.AggregationFramework.{ PipelineOperator, Set }
val pipeline = List[PipelineOperator](
Set(BSONDocument("age" -> BSONDocument(
f"$$add" -> BSONArray(f"$$age", 2)))))
coll.findAndUpdateWithPipeline(
BSONDocument("name" -> "James"),
pipeline,
fetchNewObject = true).map(_.value)
// on success, return the update document: { "age": 17 }
}
Attributes
- arrayFilters
an array of filter documents that determines which array elements to modify for an update operation on an array field
- bypassDocumentValidation
the flag to bypass document validation during the operation (default:
false
)- collation
the collation
- fetchNewObject
the command result must be the new object instead of the old one (default:
false
)- fields
the projection fields
- maxTime
the time limit for processing operations on a cursor (
maxTimeMS
)- selector
the document selector
- sort
the document indicating the sort criteria (default:
None
)- swriter
the writer for the selector
- update
the aggregation pipeline
- 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
)- writeConcern
the writer concern to be used
- writer
the writer to create the document
Returns an unordered builder for insert operations. Uses the default write concern.
Returns an unordered builder for insert operations. Uses the default write concern.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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.one(singleDoc) def many(coll: BSONCollection, multiInserts: Iterable[BSONDocument])( implicit ec: ExecutionContext) = coll.insert.many(multiInserts)
Returns a builder for insert operations. Uses the default write concern.
Returns a builder for insert operations. Uses the default write concern.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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)
Returns an ordered builder for insert operations.
Returns an ordered builder for insert operations.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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)
Returns a builder for insert operations.
Returns a builder for insert operations.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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)
Returns a builder for insert operations. Uses the default write concern.
Returns a builder for insert operations. Uses the default write concern.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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)
- ordered
the ordered behaviour
Returns a builder for insert operations.
Returns a builder for insert operations.
Attributes
- T
The type of the document to insert. An implicit
Writer[T]
typeclass for handling it has to be in the scope.- 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)
- ordered
the ordered behaviour
- writeConcern
the writer concern to be used
The default read concern
The default read concern
Attributes
Returns a removal modifier, to be used with findAndModify
.
Returns a removal modifier, to be used with findAndModify
.
Attributes
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns:
a string representation of the object.
- Definition Classes
- Any
Returns an unordered update builder. Uses the default write concern.
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)
}
Attributes
Returns an update builder. Uses the default write concern.
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)
}
Attributes
- ordered
the ordered behaviour
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)
Attributes
- writeConcern
the writer concern to be used
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)
Attributes
- ordered
the ordered behaviour
- writeConcern
the writer concern to be used
Returns an update builder. Uses the default write concern.
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)
Attributes
- bypassDocumentValidation
the flag to bypass document validation during the operation
- ordered
the ordered behaviour
- writeConcern
the writer concern to be used
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)
Attributes
- bypassDocumentValidation
the flag to bypass document validation during the operation
- ordered
the ordered behaviour
- writeConcern
the writer concern to be used
Returns an update modifier, to be used with findAndModify
.
Returns an update modifier, to be used with findAndModify
.
Attributes
- fetchNewObject
the command result must be the new object instead of the old one
- update
the update to be applied
- upsert
if true, creates a new document if no document is matching, otherwise if at least one document matches, an update is applied
The default write concern
The default write concern
Attributes
The read preference for the write operations (primary)
The read preference for the write operations (primary)
Attributes
Inherited methods
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]]()
)
}
Attributes
- T
The type of the result elements. An implicit
Reader[T]
typeclass for handling it has to be in the scope.- allowDiskUse
if true enables writing to temporary files (default:
false
)- batchSize
the batch size (for the aggregation cursor; if
None
use the default one)- bypassDocumentValidation
the flag to bypass document validation during the operation (default:
false
)- collation
the collation
- comment
the comment to annotation the aggregation command
- cp
the cursor producer
- cursor
aggregation cursor option (optional)
- cursorOptions
the options for the result cursor
- explain
if true indicates to return the information on the processing of the pipeline (default:
false
)- hint
the index to use (either the index name or the index document)
- maxAwaitTime
In practice, this parameter controls the duration of the long-polling behavior of the cursor.
- pipeline
the aggregation pipeline
- readConcern
the read concern
- readPreference
$readPrefParam
- reader
the result reader
- writeConcern
the writer concern to be used
- Inherited from:
- GenericCollectionWithAggregatorContext (hidden)
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))
Attributes
- maxDocuments
the maximum number of documents this capped collection can contain
- size
the size of the collection (number of bytes)
- Inherited from:
- CollectionMetaCommands (hidden)
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)
Attributes
- failsIfExists
if true fails if the collection already exists (default: false)
- writeConcern
the write concern for collection operations
- Inherited from:
- CollectionMetaCommands (hidden)
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")
}
Attributes
- Inherited from:
- CollectionMetaCommands (hidden)
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))
Attributes
- maxDocuments
the maximum number of documents this capped collection can contain
- size
the size of the collection (number of bytes)
- See also:
convertToCapped
- Inherited from:
- CollectionMetaCommands (hidden)
Creates a view on this collection, using an aggregation pipeline.
Creates a view on this collection, using an aggregation pipeline.
Attributes
- collation
the view collation
- name
the name of the view to be created
- operator
the first (required) operator for the aggregation pipeline
- pipeline
the other pipeline operators
- 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") }
- Inherited from:
- GenericCollectionMetaCommands (hidden)
The database which this collection belongs to.
Attributes
- Inherited from:
- DeleteCommand (hidden)
Returns the distinct values for a specified field across a single collection.
Returns the distinct values for a specified field across a single collection.
Attributes
- M
the container, that must be a scala.collection.Iterable
- T
the element type of the distinct values
- collation
$collationParam
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)
- key
the field for which to return distinct values
- readConcern
$readConcernParam
- selector
$selectorParam, that specifies the documents from which to retrieve the distinct values.
- Inherited from:
- GenericCollectionWithDistinctOps (hidden)
Attributes
- Inherited from:
- DistinctOp (hidden)
Attributes
- Inherited from:
- DistinctOpCompat (hidden)
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)
Attributes
- failIfNotFound
the flag to request whether it should fail
- Inherited from:
- CollectionMetaCommands (hidden)
Drops this collection.
Drops this collection.
The returned future will be completed with an error if this collection does not exist.
Attributes
- Inherited from:
- CollectionMetaCommands (hidden)
Returns a hint for the given index specification
document.
Returns a hint for the given index specification
document.
Attributes
- specification
the index specification document
- Inherited from:
- HintFactory (hidden)
Returns a hint for the given index name
.
Returns a hint for the given index name
.
Attributes
- name
the index name
- Inherited from:
- HintFactory (hidden)
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
})
Attributes
- Inherited from:
- CollectionMetaCommands (hidden)
The name of the collection.
Attributes
- Inherited from:
- GenericCollectionWithCommands (hidden)
Attributes
- Inherited from:
- GenericCollectionWithCommands (hidden)
Attributes
- Inherited from:
- GenericCollectionWithCommands (hidden)
The command runner
The command runner
Attributes
- Inherited from:
- GenericCollectionWithCommands (hidden)
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)
Attributes
- scale
the scale factor (for example, to get all the sizes in kilobytes)
- Inherited from:
- CollectionMetaCommands (hidden)
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)
Attributes
- Inherited from:
- CollectionMetaCommands (hidden)
'''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
Attributes
- T
the type into which Change Events are deserialized
- fullDocumentStrategy
if set to UpdateLookup, every update change event will be joined with the ''current'' version of the relevant document.
- maxAwaitTimeMS
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.
- 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).
- reader
the reader of the resulting change events
- Since:
MongoDB 3.6
- Inherited from:
- ChangeStreamOps
Concrete fields
Upper MongoDB version (used for version checks)
Upper MongoDB version (used for version checks)
Attributes
Inherited fields
Attributes
- Inherited from:
- UpdateOps
Implicits
Implicits
Inherited implicits
Attributes
- Inherited from:
- CommandCodecsWithPack (hidden)
Attributes
- Inherited from:
- UpdateCommand (hidden)