This repository contains a very basic example application built with the pymongo MongoDB Driver that connects to MongoDB Atlas. You can use this application as a starting point and reference when building your Python applications.
To build and run this project, you will need:
- Python 3.7 or higher
- The
pymongo
module - The
dnspython
module - An Atlas account
The following instructions explain how to get this project connected to your instance of MongoDB Atlas.
To get started with this sample project, download this repository to your programming environment. You can clone this project using Git version control:
git clone git@github.com:mongodb-university/atlas_starter_python.git
Or you can download the ZIP archive using your browser. If you download this project as a ZIP archive, unzip the archive before proceeding.
You can use pip
to install the necessary Python modules.
pip install pymongo dnspython
-
Open the
atlas-starter.py
file. -
On line 8, replace the placeholder text with the connection string to your Atlas cluster. For more information on finding your connection string, see the Atlas documentation.
client = pymongo.MongoClient(
"mongodb+srv://<username>:<password>@<cluster-name>/test?retryWrites=true&w=majority")
-
At your command prompt, navigate to the
atlas_starter_python
directory. -
Run the program:
python atlas-starter.py
Assuming you have the correct connection string, you'll see the program output. Have fun modifying the code to experiment with pymongo and MongoDB.
Are you having trouble getting connected to your MongoDB Atlas instance? Double-check the following:
-
Have you replaced the placeholder text with a valid connection string provided by the Atlas UI? Read more here for further context.
-
Have you whitelisted your current IP address in the Atlas UI?