Skip to content

Commit 8c2482a

Browse files
committed
first draft
1 parent e721d24 commit 8c2482a

File tree

9 files changed

+249
-134
lines changed

9 files changed

+249
-134
lines changed

source/get-started.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.. _csharp-get-started:
2+
3+
============================
4+
Get Started with the {+driver-short+}
5+
============================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: tutorial
16+
17+
.. meta::
18+
:description: Learn how to create an app to connect to MongoDB deployment by using the .NET/C# driver.
19+
:keywords: quick start, tutorial, basics
20+
21+
.. toctree::
22+
23+
Download Driver </get-started/download-driver/>
24+
Deploy a Cluster </get-started/deploy-cluster/>
25+
Create a Connection String </get-started/create-connection-string/>
26+
Databases & Collections </get-started/databases-collections/>
27+
Run a Sample Query </get-started/run-sample-query/>
28+
29+
Overview
30+
--------
31+
32+
The {+driver-short+} is a NuGet package that you can use to connect
33+
to and communicate with MongoDB. This guide shows you how to create an
34+
application that uses the {+driver-short+} to connect to a MongoDB cluster hosted on
35+
MongoDB Atlas.
36+
37+
.. tip::
38+
39+
MongoDB Atlas is a fully managed cloud database service that hosts your MongoDB
40+
deployments. You can create your own free (no credit card required) MongoDB Atlas
41+
deployment by following the steps in this guide.
42+
43+
Follow this guide to connect a sample {+language+} application to a MongoDB Atlas
44+
deployment. If you prefer to connect to MongoDB using a different driver or
45+
programming language, see our :driver:`list of official drivers <>`.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.. _csharp-get-started-connection-string:
2+
3+
==========================
4+
Create a Connection String
5+
==========================
6+
7+
You can connect to your MongoDB deployment by providing a
8+
**connection URI**, also called a *connection string*, which
9+
instructs the driver on how to connect to a MongoDB deployment
10+
and how to behave while connected.
11+
12+
The connection string includes the hostname or IP address and
13+
port of your deployment, the authentication mechanism, user credentials
14+
when applicable, and connection options.
15+
16+
.. tip::
17+
18+
To connect to a self-managed (non-Atlas) deployment, see
19+
:ref:`csharp-connection-targets`.
20+
21+
.. procedure::
22+
:style: connected
23+
24+
.. step:: Find your MongoDB Atlas Connection String
25+
26+
To retrieve your connection string for the deployment that
27+
you created in the :ref:`previous step <csharp-get-started-deploy-cluster>`,
28+
log into your Atlas account and navigate to the
29+
:guilabel:`Database` section and click the :guilabel:`Connect` button
30+
for your new deployment.
31+
32+
.. figure:: /includes/figures/atlas_connection_select_cluster.png
33+
:alt: The connect button in the clusters section of the Atlas UI
34+
35+
Proceed to the :guilabel:`Connect your application` section and select
36+
"C# / .NET" from the :guilabel:`Driver` selection menu and the version
37+
that best matches the version you installed from the :guilabel:`Version`
38+
selection menu.
39+
40+
Select the :guilabel:`Password (SCRAM)` authentication mechanism.
41+
42+
Deselect the :guilabel:`Include full driver code example` option to view
43+
the connection string.
44+
45+
.. step:: Copy your Connection String
46+
47+
Click the button on the right of the connection string to copy it to
48+
your clipboard as shown in the following screenshot:
49+
50+
.. figure:: /includes/figures/atlas_connection_copy_string.png
51+
:alt: The connection string copy button in the Atlas UI
52+
53+
.. step:: Update the Placeholders
54+
55+
Paste this connection string into a file in your preferred text editor
56+
and replace the ``<username>`` and ``<password>`` placeholders with
57+
your database user's username and password.
58+
59+
Save this file to a safe location for use in the next step.
60+
61+
.. step:: Set an Environment Variable
62+
63+
In your shell, run the following code to save your MongoDB
64+
:ref:`connection string <csharp-connect-to-mongodb>` to an
65+
environment variable. Replace ``<your MongoDB URI>`` with the connection
66+
string that you copied in the previous step.
67+
68+
.. code-block:: bash
69+
70+
export MONGODB_URI="<your MongoDB URI>"
71+
72+
.. note:: PowerShell
73+
74+
If you're using Microsoft PowerShell, run the following command instead:
75+
76+
.. code-block:: bash
77+
78+
set MONGODB_URI="<your MongoDB URI>"
79+
80+
Storing your credentials in an environment variable is safer than hardcoding them
81+
in your source code.
82+
83+
After completing these steps, you have a connection string that
84+
contains your database username and password.
85+
86+
.. include:: /includes/get-started/quickstart-troubleshoot.rst
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.. _csharp-get-started-deploy-cluster:
2+
3+
==============================
4+
Deploy a MongoDB Atlas Cluster
5+
==============================
6+
7+
You can create a free tier MongoDB deployment on MongoDB Atlas
8+
to store and manage your data. MongoDB Atlas hosts and manages
9+
your MongoDB database in the cloud.
10+
11+
.. procedure::
12+
:style: connected
13+
14+
.. step:: Create a Free MongoDB Deployment on Atlas
15+
16+
Complete the :atlas:`Get Started with Atlas </getting-started>`
17+
guide to set up a new Atlas account and load sample data into a new free
18+
tier MongoDB deployment.
19+
20+
.. step:: Save your Credentials
21+
22+
After you create your database user, save that user's
23+
username and password to a safe location for use in an upcoming step.
24+
25+
After you complete these steps, you have a new free tier MongoDB
26+
deployment on Atlas, database user credentials, and sample data loaded
27+
in your database.
28+
29+
.. include:: /includes/get-started/quickstart-troubleshoot.rst
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _csharp-get-started-download-driver:
2+
3+
========================
4+
Download the {+driver-short+}
5+
========================
6+
7+
.. procedure::
8+
:style: connected
9+
10+
.. step:: Create a Project Directory
11+
12+
In your shell, run the following commands to create a
13+
directory called ``csharp-quickstart`` and initialize a {+framework+} project for
14+
a new console application:
15+
16+
.. code-block:: bash
17+
18+
mkdir csharp-quickstart
19+
cd csharp-quickstart
20+
dotnet new console
21+
22+
.. step:: Install {+driver-short+}
23+
24+
Run the following command to install the current version of the {+driver-short+}
25+
as a dependency of your project:
26+
27+
.. code-block:: bash
28+
29+
dotnet add package MongoDB.Driver
30+
31+
After you complete these steps, you have a new {+framework+} project
32+
and the {+driver-short+} installed.
33+
34+
.. include:: /includes/get-started/quickstart-troubleshoot.rst
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. _csharp-get-started-run-sample-query:
2+
3+
==================
4+
Run a Sample Query
5+
==================
6+
7+
.. procedure::
8+
:style: connected
9+
10+
.. step:: Create your {+lang-framework+} Application
11+
12+
Copy and paste the following code into the ``Program.cs`` file in your application:
13+
14+
.. literalinclude:: /includes/quick-start/Program.cs
15+
:language: csharp
16+
:dedent:
17+
18+
.. step:: Run your Application
19+
20+
In your shell, run the following command to start this application:
21+
22+
.. code-block:: sh
23+
24+
dotnet run csharp-quickstart.csproj
25+
26+
The output includes details of the retrieved movie document:
27+
28+
.. code-block:: none
29+
30+
{
31+
_id: ...,
32+
plot: 'A young man is accidentally sent 30 years into the past...',
33+
genres: [ 'Adventure', 'Comedy', 'Sci-Fi' ],
34+
...
35+
title: 'Back to the Future',
36+
...
37+
}
38+
39+
.. tip::
40+
41+
If you encounter an error or see no output, ensure that you specified the
42+
proper connection string, and that you loaded the
43+
sample data.
44+
45+
After you complete these steps, you have a working application that
46+
uses the driver to connect to your MongoDB deployment, runs a query on
47+
the sample data, and prints out the result.
48+
49+
.. include:: /includes/get-started/quickstart-troubleshoot.rst
222 KB
Loading
34.6 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. note::
2+
3+
If you run into issues on this step, ask for help in the
4+
:community-forum:`MongoDB Community Forums <tag/python/>`
5+
or submit feedback by using the :guilabel:`Rate this page`
6+
tab on the right or bottom right side of this page.

source/quick-start.txt

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)