@@ -28,8 +28,6 @@ or set up a runnable project with examples from our Usage Guide.
2828
2929- `Source Code <https://github.com/mongodb/mongo-rust-driver/>`__
3030
31-
32-
3331Installation
3432------------
3533
@@ -40,82 +38,86 @@ See `Installation <https://github.com/mongodb/mongo-rust-driver#Installation>`__
4038Connect to MongoDB Atlas
4139------------------------
4240
43- Select from the :guilabel:`Sync` or :guilabel:`Async` tabs below for
44- corresponding connection code samples.
45-
46- .. include:: /includes/atlas-connect-blurb.rst
41+ You can use the connection snippets in the following tabs to test your
42+ connection to your MongoDB deployment on Atlas. Select from the
43+ :guilabel:`Sync` or :guilabel:`Async` tabs below for corresponding
44+ connection code samples.
4745
4846.. tabs::
4947
5048 .. tab:: Async
5149 :tabid: rust-async
5250
53- The default async runtime used by the driver is ``tokio``. To use a
54- different runtime, see
55- `Configuring the async runtime <https://github.com/mongodb/mongo-rust-driver#configuring-the-async-runtime>`__.
51+ .. note::
52+
53+ The default async runtime used by the driver is ``tokio``. To use a
54+ different runtime, see
55+ `Configuring the async runtime <https://github.com/mongodb/mongo-rust-driver#configuring-the-async-runtime>`__.
5656
57- .. code-block:: rust
57+ .. literalinclude:: /includes/connection-snippets/scram/rust-connection-async.rs
58+ :language: rust
5859
59- use mongodb::{bson::doc, options::ClientOptions, Client};
60+ .. tab:: Sync
61+ :tabid: rust-sync
6062
61- #[tokio::main]
62- async fn main() -> mongodb::error::Result<()> {
63- // Parse your connection string into an options struct
64- let mut client_options =
65- ClientOptions::parse("mongodb+srv://<username>:<password>@<cluster-url>/test?w=majority")
66- .await?;
63+ .. important::
64+
65+ You must enable the sync API in your application to use the
66+ synchronous framework. See
67+ `Enabling the sync API <https://github.com/mongodb/mongo-rust-driver#enabling-the-sync-api>`__
68+ for more details.
6769
68- // Manually set an option
69- client_options.app_name = Some("Rust Demo".to_string());
70+ .. literalinclude:: /includes/connection-snippets/scram/rust-connection-sync.rs
71+ :language: rust
72+
73+ This connection snippet uses the {+stable-api+} feature, which you can
74+ enable when using the Rust driver v2.0 and later to connect to MongoDB
75+ Server v5.0 and later. When you use this feature, you can update your driver or server without
76+ worrying about backward compatibility issues with any commands covered by the
77+ {+stable-api+}.
7078
71- // Get a handle to the cluster
72- let client = Client::with_options(client_options)?;
79+ To learn more about the {+stable-api+} feature, see the :manual:`Server
80+ manual </reference/stable-api/>`.
7381
74- // Ping the server to see if you can connect to the cluster
75- client
76- .database("admin")
77- .run_command(doc! {"ping": 1}, None)
78- .await?;
79- println!("Connected successfully.");
82+ .. include:: /includes/stable-api-notice.rst
8083
81- // List the names of the databases in that cluster
82- for db_name in client.list_database_names(None, None).await? {
83- println!("{}", db_name);
84- }
85- Ok(())
86- }
84+ .. _connect-atlas-no-stable-api-php-driver:
8785
88- .. tab:: Sync
89- :tabid: rust-sync
86+ Connect to MongoDB Atlas Without the Stable API
87+ -----------------------------------------------
9088
91- Make sure you enabled the sync API. See
92- `Enabling the sync API <https://github.com/mongodb/mongo-rust-driver#enabling-the-sync-api>`__
93- for more details.
89+ If you are using a version of MongoDB or the driver that doesn't support the
90+ {+stable-api+}, you can use the connection snippets in the following
91+ tabs to test your connection to your MongoDB deployment on Atlas. Select from the
92+ :guilabel:`Sync` or :guilabel:`Async` tabs below for corresponding
93+ connection code samples.
9494
95- .. code-block:: rust
95+ .. tabs::
9696
97- use mongodb::{bson::doc, sync::Client};
97+ .. tab:: Async
98+ :tabid: rust-async-no-stableapi
9899
99- fn main() -> mongodb::error::Result<()> {
100- // Get a handle to the cluster
101- let client = Client::with_uri_str(
102- "mongodb+srv://<username>:<password>@<cluster-url>/test?w=majority",
103- )?;
100+ .. note::
101+
102+ The default async runtime used by the driver is ``tokio``. To use a
103+ different runtime, see
104+ `Configuring the async runtime <https://github.com/mongodb/mongo-rust-driver#configuring-the-async-runtime>`__.
104105
105- // Ping the server to see if you can connect to the cluster
106- client
107- .database("admin")
108- .run_command(doc! {"ping": 1}, None)?;
109- println!("Connected successfully.");
106+ .. literalinclude:: /includes/connection-snippets/scram/rust-connection-no-stableapi-async.rs
107+ :language: rust
108+
109+ .. tab:: Sync
110+ :tabid: rust-sync-no-stableapi
110111
111- // List the names of the databases in that cluster
112- for db_name in client.list_database_names(None, None)? {
113- println!("{}", db_name);
114- }
115- Ok(())
116- }
112+ .. important::
113+
114+ You must enable the sync API in your application to use the
115+ synchronous framework. See
116+ `Enabling the sync API <https://github.com/mongodb/mongo-rust-driver#enabling-the-sync-api>`__
117+ for more details.
117118
118- .. include:: /includes/serverless-compatibility.rst
119+ .. literalinclude:: /includes/connection-snippets/scram/rust-connection-no-stableapi-sync.rs
120+ :language: rust
119121
120122Connect to a MongoDB Server on Your Local Machine
121123-------------------------------------------------
0 commit comments