.. _rust-language-center:

.. include:: /includes/unicode-checkmark.rst

===================
MongoDB Rust Driver
===================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: twocols

Introduction
------------

This is the official MongoDB Rust Driver.

.. admonition:: Alpha Release
   :class: important

   The MongoDB Rust Driver is currently in alpha.

- `Usage Guide <https://github.com/mongodb/mongo-rust-driver#example-usage>`__

- `API Reference <https://docs.rs/mongodb/latest/mongodb/>`__

- `Changelog <https://github.com/mongodb/mongo-rust-driver/releases>`__

- `Source Code <https://github.com/mongodb/mongo-rust-driver/>`__


Installation
------------

See `Installation <https://github.com/mongodb/mongo-rust-driver#Installation>`__


Connect to MongoDB Atlas
------------------------

.. include:: /includes/atlas-connect-blurb.rst

.. code-block:: rust

   use bson::doc;
   use mongodb::{options::ClientOptions, Client};

   fn main() -> mongodb::error::Result<()> {
       // Parse a connection string into an options struct.
       let mut client_options =
           ClientOptions::parse("mongodb+srv://<username>:<password>@<cluster-url>/test?w=majority")?;

       // Manually set an option.
       client_options.app_name = Some("Rust Demo".to_string());

       // Get a handle to the deployment.
       let client = Client::with_options(client_options)?;

       client
           .database("admin")
           .run_command(doc! {"ping": 1}, None)?;
       println!("Connected successfully.");

       // List the names of the databases in that deployment.
       for db_name in client.list_database_names(None)? {
           println!("{}", db_name);
       }
       Ok(())
   }

Compatibility
-------------

MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/mongodb-compatibility-table-rust.rst

Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/language-compatibility-table-rust.rst

.. include:: /includes/help-links-rust.rst
