0% found this document useful (0 votes)
37 views

Prac 4

The document discusses developing a Python program to perform CRUD operations on a MongoDB database. It provides background on MongoDB and pymongo, explaining that pymongo allows Python programs to query, insert, update, and delete data in MongoDB. It also defines the four CRUD operations - Create, Read, Update, and Delete - and provides examples of how each operation would be performed. The code section then demonstrates creating a MongoDB collection and documents, reading from the collection, updating and deleting documents, and performing all CRUD operations on an audio data collection.

Uploaded by

Eklavya Sudan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Prac 4

The document discusses developing a Python program to perform CRUD operations on a MongoDB database. It provides background on MongoDB and pymongo, explaining that pymongo allows Python programs to query, insert, update, and delete data in MongoDB. It also defines the four CRUD operations - Create, Read, Update, and Delete - and provides examples of how each operation would be performed. The code section then demonstrates creating a MongoDB collection and documents, reading from the collection, updating and deleting documents, and performing all CRUD operations on an audio data collection.

Uploaded by

Eklavya Sudan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical - 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.

4. Database and Collection:


Description: In MongoDB, data is stored in databases, each of which can contain multiple collections.
Key Points:
 A database is a container for collections, and a collection is a group of MongoDB documents.

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.

6. BSON (Binary JSON):


Description: BSON is a binary representation of JSON-like documents used in MongoDB to store and
transmit data efficiently.
Key Points:
 BSON includes various data types and structures, making it suitable for storing complex data
in MongoDB.

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.

CODE AND OUTPUT:


Read

Create new.

Update

Delete

Audio insert

Audio read.
Update audio

Delete Audio

You might also like