Announcing the Official MongoDB Rust Driver
I’m delighted to announce that we are releasing our first alpha build of MongoDB’s new official Rust driver.
Rust at MongoDB
MongoDB has a surprisingly long history with Rust. In 2013, two interns wrote a prototype Rust driver for the database targeting Rust 0.7. Still, because the Rust language was evolving quickly and making breaking changes then, the code eventually became outdated.
As an intern in the summer of 2015, I was part of a team writing a Rust driver prototype targeting Rust 1.0—released less than two weeks before the internship started! We worked hard on the driver that summer with the knowledge that the code we wrote would continue working indefinitely on newer Rust compilers. At the end of the summer, we published our completed driver prototype onto crates.io under the crate name MongoDB.
Almost four and a half years later, that driver still has an active user base; the crate has over 300,000 downloads, and GitHub issues and pull requests have shown us that users are eager for a driver that’s more than a prototype. We also see this enthusiasm reflected by the rise of Rust in developer communities. The most recent programming language rankings compiled by Steve O’Grady at Redmonk is a testament to this. To quote Steve’s commentary on Rust:
For a systems language to continue its upward trajectory in this fashion suggests that some combination of the design, the language’s community and market demand is combining to have it outperform its natural expectations.
Over the past several months, my team at MongoDB has been working on a new Rust driver written from scratch that we can commit to supporting at the same level as our other official drivers. I’m pleased to announce that we’re releasing the first alpha of an officially supported Rust driver for MongoDB—today!
Why Build a New Rust Driver?
Once we built an officially supported Rust driver, we quickly decided that writing a new driver from scratch, rather than updating the prototype, would be the best approach for us and the community. The prototype became famous for an unsupported driver and succeeded quite well as proof that a driver could be written in Rust. Monitoring MongoDB’s topology state in the background, selecting the server for each operation, and managing a pool of connections for each server—every one of these components needs to be implemented efficiently in its own right and can’t block any of the other components from performing their tasks.
Furthermore, although we were starting work before Rust had stabilized async/await and would be targeting stable Rust for our initial release, we needed to minimize the difficulties of converting the drivers’ internals to async down the line, which would have been quite tricky without careful upfront design.
Supported Features Today
The Rust driver supports all MongoDB server versions from 3.6 up and requires Rust 1.39 or newer. It fully supports standalone instances, replica sets, and sharded clusters. It implements native TLS using the Rustls crate and SCRAM-SHA-1 and SCRAM-SHA-256 authentication.
The driver supports connecting to both MongoDB Atlas and on-premise deployments. Through the bson crate, the driver supports using Serde to serialize and deserialize documents written to and from the database.
Y.T. Chung, the original author of the bson crate, has also agreed to transfer ownership of the crate to us, allowing us to develop it alongside the driver. Thanks to Y.T. for all the excellent work on the crate over the years!
What Features Are Next?
In the future, the next thing we plan to implement for the driver is async support; we’ve designed the driver architecture from the outset to convert it to async when ready. When that happens, the driver will continue providing the same sync API it offers today by wrapping the async API.
After that, we’ll implement newer database features not yet supported by this alpha release—change streams, sessions, retriable reads and writes, multi-document ACID transactions, and more will all be coming!
Original post by Sam Rossi
For full article https://www.mongodb.com/blog/post/announcing-the-official-mongodb-rust-driver