EXP – 1 : Installation of MONGO DB
EXP – 2 :
Create a collection Hobbies with following keys :
Roll Number
Name
Age
Gender
Mobile Number
Hobbies
Create a collection of 60 students data
QUERIES :
- Display all the students all the students who are boys
- Display the names of students starting with letter ‘S’
- Display the students whose name ends with ‘S’
- Display the students who have sports as their hobby
- Display the students who have more than two hobbies
- Display the details with roll number, name, and mobile number
- Display whose age is less exactly 20.
EXP – 3 :
Create collection marks and store your Sem 4 data with columns as roll number, gender,
subject/course code : Marks , Total and Percentage
Create student marks with roll number, name, branch and three subject marks
o Implement CRUD Operations
o Create collection with only roll number and 4 subject marks
o Add new column as total and percentage [using formula]
o Display the students who failed in MGT41
o Display the students who got above 70 in MGT42
o Display the students who got 60%-70% on an aggregate
o Display the class toppers in each subject – gender wise
EXP – 4 :
Implement aggregate functions for the following :
o Sort
o Count
o Projection
o Skip
o Limit
QUERIES :
o Skip first four documents from student collection
db.student.find().skip(4).pretty()
o Skip first four documents from student collection and limit to two documents
db.student.find().skip(4).limit(2).pretty()
o Display last 5 documents
db.student.skip(count()-5).limit(5)
EXP – 5 :
Implement null values in documents.
QUERY :
o To add new column to the collection as category
db.student.update({},{$set:{category:null}})
If update is used only one document will be updated. To update all documents,
use update many
db.student.updateMany({ }, ($set:{category:null})
o Update category with your category for your roll number :
db.student.update({roll number : 202805},($Set :{OC})
o Remove category field from student collection where value is assigned as BC
db.student.updateMany({category: ‘BC’},{unset: “BC”})
EXP – 6 :
Implementing arrays.
QUERY :
o Create collection food with columns as fruits and vegetables, custormer ID. And total
amount.
Custoemer ID Fruits Vegetables
1 Apple, grape , banana Carrot
2 Watermelon Potatoes, Peas
3 Mangoes, watermelon Broccoli, lettuce
o Create database as market
Use market
o Create collection food
Db.createcollection(“food”)
o Insert docs all at a time
Db.food.insertMany [{Cust ID : 1, {fruits:[ ]},{vegetable :[ ] },
{Cust ID : 1, {fruits:[ ]},{vegetable :[ ] } ]
o Find the document containing fruits as ‘banana’ and ‘mango’
db.food.find({fruits : [‘banana’,’mango’]}).pretty()
o Display the number of customers who purchased mangoes
db.food.find({fruits : ‘mango’ }).count()
o display customers who purchased only two types of fruits :
db.food.find(
o display the documents who purchased three vegetables but display only first two
vegetables:
db.food.find({vegetables:{$size3}
o update the document with mango at index 1 and replace it with cherry
db.food.find({“frutis.1”:”mango”})
db.food.update({“fruits.1”: “mango”},{$push:{fruits: “cherry”}})
To create a database , command : use <dbname>
To create collection : db.createcollection(name,options)
To display the collections : Show collections
To create document : db.dbname.insert( )
To find : db.sem4.find()
EXP – 4 :
TASK :
The table contains following information : roll number, name, m1, m2 and m3
o Display the columns roll number, m1
db.collectionname.find({ },{roll number :1 , m1 : 1 })
o Arrange the data in descending order of m2
Db.collectionamme.find().sort({m2:-1})
o Display the roll numbers and marks above 60 in m3
Db.collectionname.find({ m3:{$gt:60}}, {Rollnumber:1,m3:1}).sort({m3: -1}})
o Display the number of students failed in m2
Db.collectionname.count({m2:{$lt:40}})