Reactive Scala Driver for MongoDB
Asynchronous & Non-Blocking
You can setup this serialization pack by adding the following dependency in your
If the dependency for the Play plugin (with the right version) is present, it already provides the JSON support and this JSON serialization pack must not be added as a separate dependency.
Then, the following code enables this JSON serialization pack.
Documents and values
There is one Play JSON class for most of the BSON types, all in the
|BSONDBPointer||No JSON type|
|BSONMaxKey||No JSON type|
|BSONMinKey||No JSON type|
|BSONNull||No JSON type|
|BSONUndefined||No JSON type|
Consequently, any type that can be serialized as JSON can be also be serialized as BSON.
A document is represented by
JsObject, which is basically an immutable list of key-value pairs. Since it is the most used JSON type, one of the main focuses of the ReactiveMongo Play JSON library is to manage such
JsObjects as easy as possible. The encode of such JSON object needs an instance of the typeclass
This library provides a specialized collection called
reactivemongo.play.json.JSONCollection that deals naturally with
JsObject. Thanks to it, you can now fetch documents from MongoDB in the JSON format, transform them by removing and/or adding some properties, and send them to the client.
Even better, when a client sends a JSON document, you can validate it and transform it before saving it into a MongoDB collection (coast-to-coast approach).
The support of Play JSON for ReactiveMongo provides some extensions of the result cursors, as
.jsArray() to read underlying data as a JSON array.
Run a raw command
The command API can be used with the JSON serialization to execution a JSON object as a raw command.