Connecting to MongoDB in Python
Learn about the Python driver for MongoDB and how to use it to connect to your Python applications.
Connecting to MongoDB in Python
Unit Overview
In this unit, you'll learn how to connect a Python application to a MongoDB Atlas cluster by using PyMongo, the official MongoDB driver for synchronous Python applications. First, you'll learn what MongoDB drivers are and how they’re used to connect applications to MongoDB. Next, you'll install PyMongo by using the pip package installer and explore best practices when creating a MongoClient instance. Finally, you'll learn how to troubleshoot some common connection and authentication issues.
Prerequisite
Lessons in This Unit
- Lesson 01: Using MongoDB Python Client Libraries
- Lesson 02: Connecting to an Atlas Cluster in Python Applications
- Lesson 03: Troubleshooting a MongoDB Connection in Python Applications
Julianna Chen I Senior Curriculum Engineer
Julianna is a Senior Curriculum Engineer on the Education team, based in Vancouver, Canada. She’s developed educational content at universities and non-profits for over ten years, and is passionate about supporting access to quality technical education worldwide.
Emily Pope | Senior Curriculum Designer
Emily is a Senior Curriculum Designer at MongoDB. Prior to MongoDB, Emily worked closely with professors at MIT and Columbia to design bootcamps in full stack development and data science at Emeritus. She also worked as an instructional designer on database and computer science learning experiences at Cengage. Emily loves learning about the everchanging tech space and is passionate about making these skills accessible to a global audience.
Hi there and welcome! In this unit, you’ll learn how to connect a Python application to a MongoDB Atlas cluster by using PyMongo.
PyMongo is the official MongoDB driver for synchronous Python applications.
I’m Julianna Chen. I’m a curriculum engineer at MongoDB, and I’ll be working with you through this unit.
It’s easy to connect a Python application to a MongoDB database. All we need is a connection string, the PyMongo driver, and an application.
By using PyMongo, we can seamlessly integrate an Atlas cluster into a variety of applications.
For example, we can use Atlas to host data that’s delivered to users by using a REST API built with Python.
MongoDB is powerful on its own. But pairing it with a programming language like Python opens up even more possibilities.
We’ll explore these possibilities throughout the course.
The lessons in this unit consist of video lectures followed by quiz questions or labs so that you can practice what you learned.
First, you’ll learn what MongoDB drivers are and how they’re used to connect applications to MongoDB.
Then, we’ll install PyMongo by using pip, the package installer for Python.
We’ll create a MongoClient instance in our Python code, and use it to connect to an Atlas cluster.
Finally, we’ll troubleshoot a few common connection and authentication issues, such as: Incorrect user credentials, network access issues, and an incorrectly entered connection string.
Before you begin this unit, you should have a basic understanding of: Python, the MongoDB database and document model, and Atlas, the MongoDB developer data platform.
You’ll also need to set up an Atlas account with a Free Tier cluster.
By the end of this unit, you’ll be able to install PyMongo, use your connection string to connect your application to Atlas, and troubleshoot common connection and authentication errors.
Let’s get started!
