I am using mongodb official driver 2.0.0-beta for rust. with web server framework (rocket 0.5).
But, I saw a lot of old tutorials that used r2d2 for pool, therefore a lot of users can log in the same time.
My question is, with the new Async Api, is there really a need for pool, or can I just use the driver itself.
Thank a lot!
Yep that’s correct! The driver internally creates connection pools for each server it connects to, so there’s no need to use r2d2 or any other connection pooling library on top of it. You can configure the pooling behavior via the connection string or via the
As a side note, we do have an ongoing project to create updated tutorials for some of the more popular web frameworks to help reduce confusion for things like this, so stay tuned for that!
@Patrick_Freed Are there any updates regarding an updated tutorial for usage with rocket? I’ve been searching all over the web how to make it work with mongo for a simple case where I have a custom struct with init method (which uses ClientOptions and
sync::Client) and I want to attach it to rocket and pass the connection to the routes. I’m confused as to how to do this, there are a lot of old stuff and the rocket_contrib crate still has only the 0.3.12 mongodb driver version supported. Will appreciate any help.
There’s currently an open PR to the rocket repo here with an updated example. Once that gets merged in, we’ll link to it from our documentation. Note that the newer version of Rocket is async, so you’ll probably need to use the regular
Client instead of the sync one.