Skip to content

Commit 40457ad

Browse files
author
Chris Cho
authored
DOCSP-17383 localhost connection (#751)
* DOCSP-17383: workshop localhost connection instructions
1 parent 48ee6cd commit 40457ad

File tree

12 files changed

+113
-36
lines changed

12 files changed

+113
-36
lines changed

source/c.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ See `Installing the MongoDB C Driver (libmongoc) and BSON library (libbson)
4242
<http://mongoc.org/libmongoc/current/installing.html>`__.
4343

4444

45+
.. _connect-atlas-c-driver:
46+
4547
Connect to MongoDB Atlas
4648
------------------------
4749

@@ -107,11 +109,15 @@ client instance, specifying a version of the Versioned API:
107109
api = mongoc_server_api_new (MONGOC_SERVER_API_V1);
108110
mongoc_client_set_server_api (client, api, &error);
109111

110-
Connect to ``localhost``
111-
------------------------
112+
Connect to a MongoDB Server on Your Local Machine
113+
-------------------------------------------------
112114

113115
.. include:: /includes/localhost-connection.rst
114116

117+
To test whether you can connect to your server, replace the connection
118+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-c-driver>` code
119+
example and run it.
120+
115121
Compatibility
116122
-------------
117123

source/csharp.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ all new projects.
4949

5050
For more information, see `Installation <https://mongodb.github.io/mongo-csharp-driver/2.12/getting_started/installation/>`__.
5151

52+
.. _connect-atlas-csharp-driver:
5253

5354
Connect to MongoDB Atlas
5455
------------------------
@@ -59,7 +60,7 @@ Connect to MongoDB Atlas
5960

6061
using MongoDB.Bson;
6162
using MongoDB.Driver;
62-
63+
6364
// Replace the uri string with your MongoDB deployment's connection string.
6465
var client = new MongoClient(
6566
"mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
@@ -86,16 +87,20 @@ client instance, specifying a version of the Versioned API:
8687

8788
// Replace <connection string> with your MongoDB deployment's connection string.
8889
var settings = MongoClientSettings.FromConnectionString("<connection string>");
89-
90+
9091
// Set the version of the Versioned API on the client.
9192
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
9293
var client = new MongoClient(settings);
9394

94-
Connect to ``localhost``
95-
------------------------
95+
Connect to a MongoDB Server on Your Local Machine
96+
-------------------------------------------------
9697

9798
.. include:: /includes/localhost-connection.rst
9899

100+
To test whether you can connect to your server, replace the connection
101+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-csharp-driver>`
102+
code example and run it.
103+
99104
Compatibility
100105
-------------
101106

source/cxx.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Installation
3636

3737
See `Installing the mongocxx driver <http://mongocxx.org/mongocxx-v3/installation/>`__.
3838

39+
.. _connect-atlas-cxx-driver:
40+
3941
Connect to MongoDB Atlas
4042
------------------------
4143

@@ -58,11 +60,15 @@ Connect to MongoDB Atlas
5860

5961
.. include:: /includes/serverless-compatibility.rst
6062

61-
Connect to ``localhost``
62-
------------------------
63+
Connect to a MongoDB Server on Your Local Machine
64+
-------------------------------------------------
6365

6466
.. include:: /includes/localhost-connection.rst
6567

68+
To test whether you can connect to your server, replace the connection
69+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-cxx-driver>` code
70+
example and run it.
71+
6672
Compatibility
6773
-------------
6874

source/go.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ The recommended way to get started using the MongoDB Go driver is by using
4545
See `Installation <https://github.com/mongodb/mongo-go-driver#installation>`__
4646
for additional ways to add the driver to your project.
4747

48+
.. _connect-atlas-go-driver:
49+
4850
Connect to MongoDB Atlas
4951
------------------------
5052

@@ -82,11 +84,15 @@ client instance, specifying a version of the Versioned API:
8284

8385
client, err := mongo.Connect(ctx, clientOptions)
8486

85-
Connect to ``localhost``
86-
------------------------
87+
Connect to a MongoDB Server on Your Local Machine
88+
-------------------------------------------------
8789

8890
.. include:: /includes/localhost-connection.rst
8991

92+
To test whether you can connect to your server, replace the connection
93+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-go-driver>` code
94+
example and run it.
95+
9096
Compatibility
9197
-------------
9298

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
To connect to a database running locally on its default port, change the
2-
connection string to ``"mongodb://localhost"``.
1+
If you need to run a MongoDB server on your local machine for development
2+
purposes instead of using an Atlas cluster, you need to complete the following:
33

4-
To connect to a database running locally, change the connection string
5-
to ``"mongodb://localhost:<port>"``.
4+
1. Download the `Community <https://www.mongodb.com/try/download/community>`__
5+
or `Enterprise <https://www.mongodb.com/try/download/enterprise>`__ version
6+
of MongoDB Server.
67

7-
Your ``mongod`` instance must be running to successfully connect to your
8-
database. For information on how to start your ``mongod`` instance,
9-
see the :manual:`Manage mongod Processes
10-
</tutorial/manage-mongodb-processes/#start-mongod-processes>` Server Manual Entry.
8+
#. `Install and configure <https://docs.mongodb.com/manual/installation/>`__
9+
MongoDB Server.
10+
11+
#. Start the server.
12+
13+
.. important::
14+
15+
Always secure your MongoDB server from malicious attacks. See our
16+
:manual:`Security Checklist </administration/security-checklist/>` for a
17+
list of security recommendations.
18+
19+
After you successfully start your MongoDB server, specify your connection
20+
string in your driver connection code.
21+
22+
If your MongoDB Server is running locally, you can use the connection string
23+
``"mongodb://localhost:<port>"`` where ``<port>`` is the port number you
24+
configured your server to listen for incoming connections.
25+
26+
If you need to specify a different hostname or IP address, see our Server
27+
Manual entry on :manual:`Connection Strings </reference/connection-string/>`.

source/motor.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ For more information on requirements and other methods of installation,
6464
see the `Motor Installation <https://motor.readthedocs.io/en/stable/installation.html>`__
6565
documentation.
6666

67+
.. _connect-atlas-motor-driver:
68+
6769
Connect to MongoDB Atlas
6870
------------------------
6971

@@ -131,11 +133,15 @@ If the connection fails, you should see the following message:
131133
For more information on the connection string, see the MongoDB Server
132134
Manual entry on :manual:`Connection String URI Format </reference/connection-string/>`.
133135

134-
Connect to ``localhost``
135-
------------------------
136+
Connect to a MongoDB Server on Your Local Machine
137+
-------------------------------------------------
136138

137139
.. include:: /includes/localhost-connection.rst
138140

141+
To test whether you can connect to your server, replace the connection
142+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-motor-driver>` code
143+
example and run it.
144+
139145
Compatibility
140146
-------------
141147

source/php.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ The preferred method of installing the PHP library is with
9595
Additional installation instructions may be found in the
9696
`library documentation <https://docs.mongodb.com/php-library/current/tutorial/install-php-library/>`_.
9797

98+
.. _connect-atlas-php-driver:
9899

99100
Connect to MongoDB Atlas
100101
------------------------
@@ -113,11 +114,15 @@ Connect to MongoDB Atlas
113114

114115
.. include:: /includes/serverless-compatibility.rst
115116

116-
Connect to ``localhost``
117-
------------------------
117+
Connect to a MongoDB Server on Your Local Machine
118+
-------------------------------------------------
118119

119120
.. include:: /includes/localhost-connection.rst
120121

122+
To test whether you can connect to your server, replace the connection
123+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-php-driver>` code
124+
example and run it.
125+
121126
Compatibility
122127
-------------
123128

source/pymongo.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ version, use the following ``pip`` command:
6565
See `Installation <https://pymongo.readthedocs.io/en/stable/installation.html>`__
6666
for more ways to install PyMongo.
6767

68+
.. _connect-atlas-pymongo-driver:
6869

6970
Connect to MongoDB Atlas
7071
------------------------
@@ -104,21 +105,25 @@ Manual entry on :manual:`Connection String URI Format </reference/connection-str
104105
Versioned API
105106
-------------
106107

107-
You can use the `Versioned API <https://docs.mongodb.com/v5.0/reference/versioned-api/>`__
108+
You can use the `Versioned API <https://docs.mongodb.com/v5.0/reference/versioned-api/>`__
108109
feature starting with MongoDB Server version 5.0 and PyMongo Driver
109-
version 3.12. When you use the Versioned API feature, you can update your
110-
driver or server without worrying about backward compatibility issues with any
111-
commands covered by the Versioned API. To use this feature, construct a
110+
version 3.12. When you use the Versioned API feature, you can update your
111+
driver or server without worrying about backward compatibility issues with any
112+
commands covered by the Versioned API. To use this feature, construct a
112113
MongoDB client instance, specifying a version of the Versioned API:
113114

114115
.. literalinclude:: /includes/versioned-api-snippets/pymongo-client.py
115116
:language: python
116117

117-
Connect to ``localhost``
118-
------------------------
118+
Connect to a MongoDB Server on Your Local Machine
119+
-------------------------------------------------
119120

120121
.. include:: /includes/localhost-connection.rst
121122

123+
To test whether you can connect to your server, replace the connection
124+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-pymongo-driver>`
125+
code example and run it.
126+
122127
Compatibility
123128
-------------
124129

source/reactive-streams.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ a dependency management system.
3636
See the :java-docs:`Installation Guide <driver-reactive/getting-started/installation/>`
3737
for more information.
3838

39+
.. _connect-atlas-reactive-streams-driver:
40+
3941
Connect to MongoDB Atlas
4042
------------------------
4143

@@ -80,11 +82,15 @@ MongoDB client instance, specifying a version of the Versioned API:
8082
.. literalinclude:: /includes/versioned-api-snippets/java-rs-client.java
8183
:language: java
8284

83-
Connect to ``localhost``
84-
------------------------
85+
Connect to a MongoDB Server on Your Local Machine
86+
-------------------------------------------------
8587

8688
.. include:: /includes/localhost-connection.rst
8789

90+
To test whether you can connect to your server, replace the connection
91+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-reactive-streams-driver>`
92+
code example and run it.
93+
8894
Compatibility
8995
-------------
9096

source/rust.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Installation
3333

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

36+
.. _connect-atlas-rust-driver:
3637

3738
Connect to MongoDB Atlas
3839
------------------------
@@ -114,11 +115,15 @@ corresponding connection code samples.
114115

115116
.. include:: /includes/serverless-compatibility.rst
116117

117-
Connect to ``localhost``
118-
------------------------
118+
Connect to a MongoDB Server on Your Local Machine
119+
-------------------------------------------------
119120

120121
.. include:: /includes/localhost-connection.rst
121122

123+
To test whether you can connect to your server, replace the connection
124+
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-rust-driver>` code
125+
example and run it.
126+
122127
Compatibility
123128
-------------
124129

0 commit comments

Comments
 (0)