You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:description: Learn how to create a MongoClient to connect to a MongoDB deployment URI and customize connection behavior.
14
15
15
16
.. contents:: On this page
16
17
:local:
@@ -21,41 +22,57 @@ Create a MongoClient
21
22
This guide shows you how to connect to a MongoDB instance or replica set
22
23
deployment by using the {+driver-short+}.
23
24
24
-
.. _csharp_connection_uri:
25
+
Overview
26
+
--------
27
+
28
+
Connecting to a MongoDB deployment requires the following components:
29
+
30
+
- **Connection URI**, also known as a *connection string*, which tells the {+driver-short+}
31
+
which MongoDB deployment to connect to.
32
+
- **MongoClient** object, which creates and sustains the connection to the MongoDB deployment
33
+
and lets you perform data operations.
34
+
35
+
You can also specify connection settings in either of these components to customize the way
36
+
the {+driver-short+} behaves while connected to MongoDB.
37
+
38
+
This guide shows you how to create a connection URI and use a ``MongoClient`` object
39
+
to connect to MongoDB.
25
40
26
41
Connection URI
27
42
--------------
28
43
29
-
A **connection URI**, also known as a *connection string*, tells the driver how to connect to a MongoDB deployment and how to behave while connected.
30
-
31
-
A standard connection string includes the following pieces:
44
+
A standard connection URI includes the following components:
32
45
33
46
.. list-table::
34
47
:widths: 20 80
35
48
:header-rows: 1
36
49
37
-
* - Piece
50
+
* - Component
38
51
- Description
39
52
40
53
* - ``mongodb://``
41
54
42
55
- Required. A prefix that identifies this as a string in the
43
56
standard connection format.
44
57
45
-
* - ``username:password@``
58
+
* - ``username:password``
46
59
47
-
- Optional. Authentication credentials. If you include these, the client will authenticate the user against the database specified in ``authSource``.
60
+
- Optional. Authentication credentials. If you include these, the client
61
+
authenticates the user against the database specified in ``authSource``.
62
+
For more information about authentication settings, see
63
+
:ref:`csharp-authentication-mechanisms`.
48
64
49
65
* - ``host[:port]``
50
66
51
-
- Required. The host and optional port number where MongoDB is running. If you don't include the port number, the driver will use the default port, ``27017``.
67
+
- Required. The host and optional port number where MongoDB is running. If you don't
68
+
include the port number, the driver uses the default port ``27017``.
52
69
53
70
* - ``/defaultauthdb``
54
71
55
72
- Optional. The authentication database to use if the
56
73
connection string includes ``username:password@``
57
74
authentication credentials but not the ``authSource`` option. If you don't include
58
-
this piece, the client will authenticate the user against the ``admin`` database.
75
+
this component, the client authenticates the user against the ``admin`` database.
59
76
60
77
* - ``?<options>``
61
78
@@ -64,37 +81,43 @@ A standard connection string includes the following pieces:
64
81
:ref:`csharp-connection-options` for a full description of
65
82
these options.
66
83
67
-
To use a connection URI, pass it as a string to the ``MongoClient`` constructor. In the
68
-
following example, the driver uses a sample connection URI to connect to a MongoDB
69
-
instance on port ``27017`` of ``localhost``:
84
+
For more information about creating a connection string, see
85
+
:manual:`Connection Strings </reference/connection-string?tck=docs_driver_csharp>` in the
86
+
MongoDB Server documentation.
87
+
88
+
MongoClient
89
+
-----------
90
+
91
+
To create a connection to MongoDB, pass a connection URI to the
92
+
``MongoClient`` constructor. In the following example, the driver uses a sample
93
+
connection URI to connect to a MongoDB deployment running on port ``27017`` of ``localhost``:
0 commit comments