Reactive Scala Driver for MongoDB
Asynchronous & Non-Blocking
The Collection API is designed to be very extensible, allowing the use of third-party libraries to build documents (e.g. use something else than the embedded BSON library).
This trait is almost empty.
All the collection implementations must mix this trait in. They also provide implicit objects of type
CollectionProducer that make new (specialized) instances of them. Since
db.collection() is parametrized with
C <: Collection and accepts an implicit
CollectionProducer[C], the returned instance of collection can be inferred to the right type if there is only one producer in the implicit scope, which is a typical situation.
Most of the implementations actually extend the trait
This trait is much more complete than
Collection. It defines common methods, like
insert, among others. One particularity of them is that they may be given …
Let’s take an example of how these types are used for
find(), which is defined like this:
This function takes a
selector (or query) of type
S. This object is then transformed into BSON thanks to the implicit
swriter parameter. Moreover, you can notice that the return type is another trait,
GenericQueryBuilder, with the same parameter type
GenericQueryBuilder, like its name says it, helps building and customizing the query.
- The default implementation in ReactiveMongo:
BSONCollection. It relies on the embedded BSON library, with
BSONDocumentWriteras the de/serializer typeclasses.
- The implementation in the Play JSON support,
JSONCollection. It uses
JsObject(a JSON object), and the de/serializer typeclasses