|
| 1 | +.. _rust-usage-examples: |
| 2 | + |
| 3 | +============== |
| 4 | +Usage Examples |
| 5 | +============== |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +Overview |
| 14 | +-------- |
| 15 | + |
| 16 | +Usage examples show runnable code examples to demonstrate frequently used MongoDB |
| 17 | +operations. Each usage example includes the following: |
| 18 | + |
| 19 | +- Description of the MongoDB operation |
| 20 | +- Asynchronous and synchronous Rust code examples that you can run in |
| 21 | + your own environment |
| 22 | +- Output printed by the code example |
| 23 | + |
| 24 | +.. TODO: To learn more about the runtimes offered by the {+driver-short+}, |
| 25 | + see <add link to runtimes page>. |
| 26 | + |
| 27 | +How to Use the Usage Examples |
| 28 | +----------------------------- |
| 29 | + |
| 30 | +The usage examples are designed to run operations on a MongoDB deployment that contains |
| 31 | +the Atlas sample datasets. When you run the example code without the sample data, the output |
| 32 | +may not match. |
| 33 | + |
| 34 | +Follow this tutorial to set up your MongoDB deployment with the sample data and run the |
| 35 | +example code in your development environment. Before performing the following actions, |
| 36 | +ensure that you create an Atlas account and deploy a cluster. For information about setting |
| 37 | +up an account and a cluster, see the :atlas:`Get Started with Atlas Guide |
| 38 | +</getting-started/#atlas-getting-started>`. |
| 39 | + |
| 40 | +.. procedure:: |
| 41 | + :style: connected |
| 42 | + |
| 43 | + .. step:: Load the Sample Datasets |
| 44 | + |
| 45 | + Follow the instructions on the :atlas:`Load Sample Data </sample-data>` page |
| 46 | + to load the sample datasets into your database deployment. |
| 47 | + |
| 48 | + .. step:: Add the Usage Example Code to Your Development Environment |
| 49 | + |
| 50 | + Copy the example code from the usage example page and paste it into a new file in |
| 51 | + your preferred directory. |
| 52 | + |
| 53 | + To learn more about creating an application that uses the {+driver-short+}, follow the |
| 54 | + :ref:`rust-quickstart`. |
| 55 | + |
| 56 | + .. step:: Replace the Connection String Placeholder |
| 57 | + |
| 58 | + In your example code, replace the ``connection string`` placeholder with your MongoDB |
| 59 | + deployment connection string. For example, if your connection string is |
| 60 | + ``"mongodb+srv://mongodb-example:27017"``, your connection string assignment resembles |
| 61 | + the following: |
| 62 | + |
| 63 | + .. code-block:: rust |
| 64 | + :copyable: false |
| 65 | + |
| 66 | + let uri = "mongodb+srv://mongodb-example:27017"; |
| 67 | + |
| 68 | + .. step:: Run the Usage Example Code |
| 69 | + |
| 70 | + Run your application in your development environment. If you run your Rust applications |
| 71 | + on the command line, run the following command: |
| 72 | + |
| 73 | + .. code-block:: bash |
| 74 | + |
| 75 | + cargo run |
| 76 | + |
| 77 | +After completing these steps, you can see the output described in the **Expected Output** section |
| 78 | +of the corresponding usage example. |
| 79 | + |
| 80 | +.. Available Usage Examples |
| 81 | +.. ------------------------ |
| 82 | + |
| 83 | +.. TODO: add Usage Example pages as they are created |
| 84 | + - :ref:`Find a Document <rust-find-one-usage>` |
| 85 | + - :ref:`Find Multiple Documents <rust-find-usage>` |
| 86 | + - :ref:`Insert a Document <rust-insert-one-usage>` |
| 87 | + - :ref:`Insert Multiple Documents <rust-insert-many-usage>` |
| 88 | + - :ref:`Update a Document <rust-update-one-usage>` |
| 89 | + - :ref:`Update Multiple Documents <rust-update-many-usage>` |
| 90 | + - :ref:`Replace a Document <rust-replace-usage>` |
| 91 | + - :ref:`Delete a Document <rust-delete-one-usage>` |
| 92 | + - :ref:`Delete Multiple Documents <rust-delete-many-usage>` |
| 93 | + - :ref:`Count Documents <rust-count-usage>` |
| 94 | + - :ref:`Find Distinct Values <rust-distinct-usage>` |
| 95 | + |
| 96 | + |
0 commit comments