Prac 4
Prac 4
AIM: Develop a python program that interacts with MongoDB. Perform CRUD Operations (Create,
Read, Update and Delete) on a sample collection.
THEORY:
1. MongoDB:
Description: MongoDB is a popular NoSQL (Not Only SQL) database that is designed for handling
large amounts of unstructured or semi-structured data. It provides high performance, high availability,
and easy scalability.
Key Characteristics:
High Performance: MongoDB is designed for high-speed read and write operations, making
it suitable for applications that require quick access to data.
High Availability: It offers features like replication and sharding to ensure continuous
availability even in case of hardware failures or other issues.
Easy Scalability: MongoDB can scale horizontally by distributing data across multiple servers,
allowing for seamless scaling as data grows.
2. pymongo:
Description: pymongo is the official Python driver for MongoDB, providing a way for Python
applications to interact with a MongoDB database.
Key Characteristics:
API for MongoDB: pymongo exposes functions and classes that allow Python programs to
perform various operations on MongoDB, such as querying, inserting, updating, and deleting
data.
Efficiency: pymongo is optimized for efficiency and performance, making it a reliable choice
for interacting with MongoDB in Python applications.
3. MongoDB Connection:
Description: Establishing a connection to a MongoDB server is a fundamental step in working with
MongoDB in Python. The pymongo.MongoClient class is used to establish this connection.
Key Points:
The connection string typically contains information about the host, port, and any
authentication details needed to connect to the MongoDB server.
5. MongoDB Document:
Description: A document in MongoDB is a record stored in a collection, similar to a row in a traditional
relational database.
Key Points:
Documents are stored in BSON (Binary JSON) format, which is a binary representation of
JSON-like key-value pairs.
Documents in MongoDB are flexible, allowing for varying structures and data types within the
same collection.
7. MongoDB Query:
Description: A MongoDB query is a way to specify criteria for retrieving specific documents from a
collection.
Key Points:
MongoDB queries use a JSON-like syntax and can include conditions based on fields, logical
operators, and comparison operators.
8. CRUD Operations
CRUD stands for Create, Read, Update, and Delete. These are the four fundamental operations that can
be performed on any data storage system, including databases. These operations allow for the basic
management and manipulation of data within a system.
Here's a breakdown of each CRUD operation:
1) Create (C):
The Create operation involves adding new data or creating a new record in the system.
This operation typically corresponds to the INSERT SQL statement in relational databases.
Example: Adding a new user to a user database.
2) Read (R):
The Read operation involves retrieving or reading data from the system without making any
changes to it.
This operation corresponds to the SELECT SQL statement in relational databases.
Example: Fetching all customer records from a customer database.
3) Update (U):
The Update operation involves modifying existing data or updating existing records in the
system.
This operation typically corresponds to the UPDATE SQL statement in relational databases.
Example: Updating the contact information for a specific user in a user database.
4) Delete (D):
The Delete operation involves removing data or deleting records from the system.
This operation typically corresponds to the DELETE SQL statement in relational databases.
Example: Removing a product entry from a product catalog.
These CRUD operations are essential for interacting with and managing data within any software
application or database system. They provide the necessary functionalities to create, retrieve, modify,
and delete data, enabling effective data management and maintenance.
Create new.
Update
Delete
Audio insert
Audio read.
Update audio
Delete Audio