Site icon Afzal Badshah, PhD

Connecting MongoDB Atlas to Google Colab

MongoDB is a popular NoSQL database management system known for its flexibility, scalability, and ease of use. Unlike traditional relational databases, MongoDB stores data in flexible, JSON-like documents, making it suitable for a wide range of applications, including web development, mobile apps, and data analytics.

MongoDB Atlas

MongoDB Atlas is a fully managed cloud database service provided by MongoDB, offering a hassle-free way to deploy, manage, and scale MongoDB databases in the cloud. With MongoDB Atlas, you can easily create and configure database clusters, handle backups and restores, and monitor performance, all without the need for complex infrastructure management.

Step 1: Register on MongoDB Atlas

Step 2: Setting up Users

Step 3: Setting up IPs

Step 4: Creating Clusters

Step 5: Getting Connection String

Google Colab Setup

Google Colab, short for Google Colaboratory, is a cloud-based platform provided by Google that allows users to write and execute Python code in a browser-based interactive environment. It offers free access to computing resources, including GPU and TPU accelerators, making it ideal for machine learning, data analysis, and collaborative research projects. With Google Colab, users can create and share Jupyter notebooks, collaborate with others in real-time, and leverage pre-installed libraries and tools, all without the need for local installations or setup.

Step 6: Basic Installation

Step 7: Basic Installation

import pymongo
from pymongo import MongoClient

Step 8: Connect to MongoDB Atlas:

client = pymongo.MongoClient("mongodb+srv://<username>:<password>@<cluster-address>/<dbname>?retryWrites=true&w=majority")

Step 9: Accessing the Database:

db = client.<dbname>
collection = db.<collectionname>

You can access the detailed tutorial here.
Exit mobile version