Practical No.
1: MongoDB Basics
Aim
To study basic MongoDB operations such as creating and dropping databases, collections,
and performing CRUD operations.
a) Create and Drop Database
Create Database
use collegeDB
Note: Database is created when data is inserted into a collection.
Drop Database
[Link]()
b) Create, Display and Drop Collection
Create Collection
[Link]("students")
Display Collections
show collections
Drop Collection
[Link]()
c) Insert, Query, Update and Delete a Document
Insert Document
[Link]({
rollNo: 1,
name: "Vikas",
age: 20,
marks: 85
})
Query Document
[Link]()
[Link]({ rollNo: 1 })
Update Document
[Link](
{ rollNo: 1 },
{ $set: { marks: 90 } }
Delete Document
[Link]({ rollNo: 1 })
Practical No. 2: Simple Queries with MongoDB
Aim
To perform simple queries in MongoDB using insert and find operations with conditions.
Procedure and Queries
Insert Multiple Documents
[Link]([
{ rollNo: 2, name: "Kaustubh", age: 20, marks: 85 },
{ rollNo: 3, name: "Dhananjay", age: 20, marks: 92 },
{ rollNo: 4, name: "Paras", age: 20, marks: 85 },
{ rollNo: 5, name: "Ajinkya", age: 19, marks: 78 }
])
Find All Documents
[Link]()
Find with Condition
[Link]({ marks: { $gt: 80 } })
Find Specific Fields
[Link]({},{ name: 1, marks: 1, _id: 0 })
Find Documents Using AND Condition
[Link]({ age: 20, marks: { $gt: 80 } })
Purpose: Displays students whose age is 20 and marks are greater than 80.
Find Documents Using OR Condition
[Link]({
$or: [
{ marks: { $gt: 90 } },
{ age: 19 }
]
})
Purpose: Displays students who have marks greater than 90 or age equal to 19.
Sort Documents
[Link]().sort({ marks: -1 })
Purpose: Displays students sorted by marks in descending order.