To use MongoDB you have to add the component components::Mongo and configure it according to the documentation. After that you can work with a collection via storages::mongo::Collection:
It is recommended to set timeouts on the server side using storages::mongo::options::MaxServerTime as for other cancellation mechanisms MongoDB does not guarantee that the cancelled operation was not applied.
For client-side timeouts consider setting socket and/or connection timeouts in pool configuration as native task cancellation is not supported in the current implementation.
Write results
Methods that modify a collection return an object storages::mongo::WriteResult containing information about the result of the operation:
In cases where the same operation is performed with the same arguments many times, it can be stored into a variable and reused. The finished operation can be passed to the collection method Execute().
Since BSON is a binary format, it is not human readable. Differences in the BSON and JSON formats type systems do not always allow you to perform conversions between them unambiguously. In this regard, we do not provide conversion functions between BSON and text formats by default, but they are available in <userver/formats/bson/serialize.hpp>. These functions are provided without guarantees for the stability of the conversion, and are primarily intended for debugging.
Mongo Congestion Control
Extra database load may lead to database overload. To protect Mongo from this happening userver has Congestion Control. In case of fast timings increase, the Congestion Control limits the number of concurrent connections to Mongo and eliminates the extra load. On the one hand, it leads to extra error responses, but on the other hand, it greatly lowers the timings of the rest of the database requests and helps Mongo to return to the normal state with lower response timings.