This is very useful when you don’t want to explicitly convert your objects into yet another different structure – if your application uses JSON, it is perfectly understandable to want to avoid using BSON only for dealing with MongoDB.
The Collection trait
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 GenericCollection.
The GenericCollection trait
This trait is much more complete than Collection. It defines common methods, like find, update, delete and 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
A 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 BSONDocumentReader and BSONDocumentWriter as the de/serializer typeclasses.
The implementation in the Play JSON support, JSONCollection. It uses JsObject (a JSON object), and the de/serializer typeclasses Writes and Reads.