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

MongoDB_Assignment (1)

The document outlines a MongoDB practice session consisting of two parts. Part A involves connecting to a MongoDB database, creating a 'student' database, inserting user records, displaying and sorting data, and performing updates and deletions on specific records. Part B focuses on inserting documents into an 'inventory' database, querying items by category, and updating or removing fields from those documents.

Uploaded by

yogucris07manutd
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)
2 views

MongoDB_Assignment (1)

The document outlines a MongoDB practice session consisting of two parts. Part A involves connecting to a MongoDB database, creating a 'student' database, inserting user records, displaying and sorting data, and performing updates and deletions on specific records. Part B focuses on inserting documents into an 'inventory' database, querying items by category, and updating or removing fields from those documents.

Uploaded by

yogucris07manutd
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/ 2

Mongo DB Practice Session -1

Part- A

1.Connect to MongoDB using the console ( by executing the mongo command )


2.Create a student database
3.Connect to student database
4.Insert following records into the "users" collection:
a. user_id: “abc1”, firstName: "Steve", lastName: "Haines", age: 39, gender : “M”
b. user_id: “abc2”, firstName: "Michael", lastName: "Obama", age: 25, gender : “M”
c. user_id: “abc3”,firstName: "Ram", lastName: "Das", age: 45, gender : “M”
d. user_id: “abc4”, firstName: "Chetan", lastName: "Barot", age: 30, gender : “M”
e. user_id: “abc5”, firstName: "Jaya", lastName: "Kumari", age: 35, gender : “F”
f. user_id: “abc6”, firstName: "Seeta", lastName: "Kumari", age: 22, gender : “F”
g. user_id: “abc7”, firstName: "Shiv", lastName: "Patil", age: 57, gender : “M”
h. user_id: “abc8”, firstName: "Rachna", lastName: "Sharma", age: 57, gender : “F”
i. user_id: “abc9”, firstName: "Alex", lastName: "Mathew", age: 48, gender : “M”
j. user_id: “abc10”, firstName: "Gracy", lastName: "Abreo", age: 72, gender : “F”
k. user_id: “abc11”, firstName: "Ranjan", lastName: "Patil", age: 60, gender : “M” "address":
{ "street": "Phase1", "zipcode": "400049", "state": "Maharashtra"
}
5. Display the data from the users collection
6. Sort the records in ascending order of age.
7. Display the records with last name Kumari
8. Display the records of gender Male.
9. Display the only first name, last name and age of users whose age is less than 30 years (Display
all fields except id and gender)
10. Display the records of age greater than 30 years
11. Display the records whose age is 57 years.
12. Update the record of user mentioned in (j), set it’s age to 73
13. Update the record of user mentioned in (d), increment it’s age by 3.
14. Remove age from the record (i)
15. Remove all the parameters for user with first name “Steve” from the record.
Part- B

1- Insert Array of document in inventory database

{
item: "ABC2",
details: { model: "14Q3", manufacturer: "M1 Corporation" },
stock: [ { size: "M", qty: 50 } ],
category: "clothing"
},
{
item: "MNO2",
details: { model: "14Q3", manufacturer: "ABC Company" },
stock: [ { size: "S", qty: 5 }, { size: "M", qty: 5 }, { size: "L", qty: 1 } ],
category: "clothing"
},
{
item: "IJK2", d
details: { model: "14Q2", manufacturer: "M5 Corporation" },
stock: [ { size: "S", qty: 5 }, { size: "L", qty: 1 } ],
category: "houseware"
}

2- Find informtion about items and details from inventory collection where category is houseware
3- Increment the quantity by 10, for item_id "IJK2"
4-Remove the category field from the document where item: "ABC2",
5-Update the name of model from "14Q3" to "14P3" for item_id MNO2

You might also like