Lab01-MongoDB-BasicOperations
Lab01-MongoDB-BasicOperations
What is NoSQL?
NoSQL (Not Only SQL) databases provide a flexible and scalable way to store and retrieve
data. Unlike traditional relational databases (SQL-based), NoSQL databases do not enforce
a fixed schema, making them ideal for handling large volumes of unstructured or semi-
structured data.
Why NoSQL?
Introduction to MongoDB
Feature Description
Graphical UI Easy-to-use interface for working with MongoDB.
View Databases & Collections Lists all databases and collections available.
Insert, Update, Delete Documents Modify records without writing MongoDB commands.
Find Query Interface Allows filtering documents using JSON-based queries.
Aggregation Pipeline Helps perform complex data processing visually.
Schema Analysis Automatically detects and displays data structure.
Index & Performance Tools Monitors query execution time and indexing.
LAB EXPERIMENT-01
1a. Install MongoDB on your system (or use a pre-configured instance). Connect to the
database using the MongoDB shell. Verify your connection by listing all the databases.
1b. Create a new database named 'my_database'. Switch to this database and create a collection
named 'students'. Insert two sample documents into the 'students' collection, each representing
a student with the following fields: 'name', 'age', 'city'.
Aim
For Windows:
{
"name": "Arjun",
"age": 22,
"city": "Bengaluru"
}
Click "Insert".
{
"name": "Priya",
"age": 21,
"city": "Chennai"
}
Click "Insert".
Expected Output: Two documents are successfully inserted into the student’s collection. The
data should now be visible in MongoDB Compass.
{}
{"name": "Arjun" }
{ "city": "Bengaluru" }
{"age": {"$gt": 21 } }
Effect: Fetches all students with age > 21.
The $or operator ensures that at least one condition inside it must be true for a document to
match.It is used to find documents that satisfy either one condition or the other.
The $and operator ensures that all conditions inside it must be true for a document to match. It
is used to find documents that satisfy multiple conditions simultaneously.
Example:
Nesting in MongoDB refers to using one logical operator ($and, $or) inside another to create
more complex queries.
Find students who are from Bengaluru or Chennai AND have age > 21:
{
"$and": [
{ "age": { "$gt": 21 } }
In this lab, we successfully installed MongoDB, connected to the database using MongoDB
Compass, created a new database and collection, and inserted sample documents. We also
verified the insertion by retrieving the stored data and demonstrated how to use the find()
function to query data efficiently.