Skip to content

Commit 5b8198e

Browse files
committed
consolidate get started
1 parent e628eed commit 5b8198e

File tree

7 files changed

+251
-259
lines changed

7 files changed

+251
-259
lines changed

config/redirects

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ raw: ${prefix}/get-started/download-and-install/ -> ${base}/current/get-started/
1414
[*-master]: ${prefix}/${version}/security/enterprise-authentication/ -> ${base}/${version}/security/authentication/
1515
[*-master]: ${prefix}/${version}/faq/ -> ${base}/${version}/
1616
[*-master]: ${prefix}/${version}/connect/connection-pools/ -> ${base}/${version}/connect/connection-options/#connection-pools
17+
[*-master]: ${prefix}/${version}/get-started/download-and-install/ -> ${base}/${version}/get-started/
18+
[*-master]: ${prefix}/${version}/get-started/create-a-deployment/ -> ${base}/${version}/get-started/
19+
[*-master]: ${prefix}/${version}/get-started/create-a-connection-string/ -> ${base}/${version}/get-started/
20+
[*-master]: ${prefix}/${version}/get-started/connect-to-mongodb/ -> ${base}/${version}/get-started/
21+
[*-master]: ${prefix}/${version}/get-started/next-steps/ -> ${base}/${version}/get-started/

source/get-started.txt

Lines changed: 246 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ Get Started with {+driver-short+}
1818
:description: Learn how to create an app to connect to MongoDB deployment by using the PyMongo driver.
1919
:keywords: quick start, tutorial, basics
2020

21-
.. toctree::
22-
23-
Download & Install </get-started/download-and-install/>
24-
Create a Deployment </get-started/create-a-deployment/>
25-
Create a Connection String </get-started/create-a-connection-string/>
26-
Connect </get-started/connect-to-mongodb/>
27-
Next Steps </get-started/next-steps/>
28-
2921
Overview
3022
--------
3123

@@ -43,3 +35,249 @@ MongoDB Atlas.
4335
Follow this guide to connect a sample Python application to a MongoDB Atlas
4436
deployment. If you prefer to connect to MongoDB using a different driver or
4537
programming language, see our :driver:`list of official drivers <>`.
38+
39+
.. _pymongo-get-started-download-and-install:
40+
41+
Download and Install
42+
--------------------
43+
44+
.. note:: Alternative Installation Methods
45+
46+
The following steps show you how to install {+driver-short+} by using
47+
`pip <https://pip.pypa.io/en/stable/installation/>`__. To install
48+
{+driver-short+} from source, see
49+
`Install from Source <https://pymongo.readthedocs.io/en/stable/installation.html#installing-from-source>`__
50+
in the API documentation.
51+
52+
.. procedure::
53+
:style: connected
54+
55+
.. step:: Install dependencies
56+
57+
Ensure you have the following dependencies installed
58+
in your development environment:
59+
60+
- `Python3 version 3.8 or later <https://www.python.org/downloads/>`__
61+
- `pip <https://pip.pypa.io/en/stable/installation/>`__
62+
- `dnspython <https://pypi.org/project/dnspython/>`__
63+
64+
.. step:: Create a project directory
65+
66+
In your shell, run the following command to create a
67+
directory called ``pymongo-quickstart`` for this project:
68+
69+
.. code-block:: bash
70+
71+
mkdir pymongo-quickstart
72+
73+
Select the tab corresponding to your operating system and run the following commands
74+
to create a ``quickstart.py`` application file in the ``pymongo-quickstart`` directory:
75+
76+
.. tabs::
77+
78+
.. tab:: macOS / Linux
79+
:tabid: create-file-mac-linux
80+
81+
.. code-block:: bash
82+
83+
cd pymongo-quickstart
84+
touch quickstart.py
85+
86+
.. tab:: Windows
87+
:tabid: create-file-windows
88+
89+
.. code-block:: bash
90+
91+
cd pymongo-quickstart
92+
type nul > quickstart.py
93+
94+
.. step:: Install {+driver-short+}
95+
96+
Select the tab corresponding to your operating system and run the following commands
97+
to create and activate a virtual environment in which to install the driver:
98+
99+
.. tabs::
100+
101+
.. tab:: macOS / Linux
102+
:tabid: venv-mac-linux
103+
104+
.. code-block:: bash
105+
106+
python3 -m venv venv
107+
source venv/bin/activate
108+
109+
.. tab:: Windows
110+
:tabid: venv-windows
111+
112+
.. code-block:: bash
113+
114+
python3 -m venv venv
115+
. venv\Scripts\activate
116+
117+
With the virtual environment activated, run the following command to
118+
install the current version of {+driver-short+}:
119+
120+
.. code-block:: bash
121+
122+
python3 -m pip install pymongo
123+
124+
After you complete these steps, you have a new project directory
125+
and the driver dependencies installed.
126+
127+
.. _pymongo-get-started-create-deployment:
128+
129+
Create a MongoDB Deployment
130+
---------------------------
131+
132+
You can create a free-tier MongoDB deployment on MongoDB Atlas
133+
to store and manage your data. MongoDB Atlas hosts and manages
134+
your MongoDB database in the cloud.
135+
136+
.. procedure::
137+
:style: connected
138+
139+
.. step:: Create a free MongoDB deployment on Atlas
140+
141+
Complete the :atlas:`Get Started with Atlas </getting-started?tck=docs_driver_python>`
142+
guide to set up a new Atlas account and load sample data into a new free
143+
tier MongoDB deployment.
144+
145+
.. step:: Save your credentials
146+
147+
After you create your database user, save that user's
148+
username and password to a safe location for use in an upcoming step.
149+
150+
After you complete these steps, you have a new free tier MongoDB
151+
deployment on Atlas, database user credentials, and sample data loaded
152+
in your database.
153+
154+
.. _pymongo-get-started-connection-string:
155+
156+
Create a Connection String
157+
--------------------------
158+
159+
You can connect to your MongoDB deployment by providing a
160+
**connection URI**, also called a *connection string*, which
161+
instructs the driver on how to connect to a MongoDB deployment
162+
and how to behave while connected.
163+
164+
The connection string includes the hostname or IP address and
165+
port of your deployment, the authentication mechanism, user credentials
166+
when applicable, and connection options.
167+
168+
To connect to an instance or deployment not hosted on Atlas, see
169+
:ref:`pymongo-connection-targets`.
170+
171+
.. procedure::
172+
:style: connected
173+
174+
.. step:: Find your MongoDB Atlas connection string
175+
176+
To retrieve your connection string for the deployment that
177+
you created in the :ref:`previous step <pymongo-get-started-create-deployment>`,
178+
log into your Atlas account and navigate to the
179+
:guilabel:`Database` section and click the :guilabel:`Connect` button
180+
for your new deployment.
181+
182+
.. figure:: /includes/figures/atlas_connection_select_cluster.png
183+
:alt: The connect button in the clusters section of the Atlas UI
184+
185+
Proceed to the :guilabel:`Connect your application` section and select
186+
"Python" from the :guilabel:`Driver` selection menu and the version
187+
that best matches the version you installed from the :guilabel:`Version`
188+
selection menu.
189+
190+
Select the :guilabel:`Password (SCRAM)` authentication mechanism.
191+
192+
Deselect the :guilabel:`Include full driver code example` option to view
193+
the connection string.
194+
195+
.. step:: Copy your connection string
196+
197+
Click the button on the right of the connection string to copy it to
198+
your clipboard as shown in the following screenshot:
199+
200+
.. figure:: /includes/figures/atlas_connection_copy_string_python.png
201+
:alt: The connection string copy button in the Atlas UI
202+
203+
.. step:: Update the placeholders
204+
205+
Paste this connection string into a file in your preferred text editor
206+
and replace the ``<username>`` and ``<password>`` placeholders with
207+
your database user's username and password.
208+
209+
Save this file to a safe location for use in the next step.
210+
211+
After completing these steps, you have a connection string that
212+
contains your database username and password.
213+
214+
.. _pymongo-get-started-connect-to-mongodb:
215+
216+
Connect to MongoDB
217+
------------------
218+
219+
.. procedure::
220+
:style: connected
221+
222+
.. step:: Create your {+driver-short+} application
223+
224+
Copy and paste the following code into the ``quickstart.py`` file in your application:
225+
226+
.. literalinclude:: /includes/get-started/connect-and-query.py
227+
:language: python
228+
:copyable:
229+
230+
.. step:: Assign the connection string
231+
232+
Replace the ``<connection string URI>`` placeholder with the
233+
connection string that you copied from the :ref:`pymongo-get-started-connection-string`
234+
step of this guide.
235+
236+
.. step:: Run your application
237+
238+
In your shell, run the following command to start this application:
239+
240+
.. code-block:: sh
241+
242+
python3 quickstart.py
243+
244+
The output includes details of the retrieved movie document:
245+
246+
.. code-block:: none
247+
248+
{
249+
_id: ...,
250+
plot: 'A young man is accidentally sent 30 years into the past...',
251+
genres: [ 'Adventure', 'Comedy', 'Sci-Fi' ],
252+
...
253+
title: 'Back to the Future',
254+
...
255+
}
256+
257+
.. tip::
258+
259+
If you encounter an error or see no output, check whether you specified the
260+
proper connection string, and that you loaded the
261+
sample data.
262+
263+
After you complete these steps, you have a working application that
264+
uses the driver to connect to your MongoDB deployment, runs a query on
265+
the sample data, and prints out the result.
266+
267+
.. _pymongo-get-started-next-steps:
268+
269+
Next Steps
270+
----------
271+
272+
Congratulations on completing the tutorial!
273+
274+
In this tutorial, you created a Python application that
275+
connects to a MongoDB deployment hosted on MongoDB Atlas
276+
and retrieves a document that matches a query.
277+
278+
Learn more about {+driver-short+} from the following resources:
279+
280+
- Learn how to perform read operations in the :ref:`<pymongo-read>` section.
281+
- Learn how to perform write operations in the :ref:`<pymongo-write>` section.
282+
283+
.. include:: /includes/get-started/quickstart-troubleshoot.rst

source/get-started/connect-to-mongodb.txt

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

source/get-started/create-a-connection-string.txt

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

0 commit comments

Comments
 (0)