Professional Documents
Culture Documents
Installing Mongo
Go to https://www.youtube.com/playlist?list=PLydSrzyx1wVOSqIUnmzxHY9dUUa2qJoXR
View video on MongoDB installation for Windows and follow step by step.
2. Create a database called dominos, if not yet existed, or start using the database.
use dominos
e.g.
use kfc
use mydb
UPDATE COMMANDS
10. Update only the first document with the name Ali to insert gender.
db.customers.updateOne({first_name:"Ali"},{$set:{gender:"male"}})
12. Ooops, Ali’s age is actually 48, use increment to add 3 to his age.
db.customers.updateOne({first_name:”Ali”}, {$inc: {age:3}})
13. Remove a name/value. In this case, age. 1 for true 0 for false.
db.customers.updateOne({first_name:”Ali”}, {$unset:{age:1}})
14. Rename a name of a name/value
db.customers.updateOne({first_name:”Ali”},{$rename:{“gender”:”sex”}})
db.customers.updateMany({first_name:”Ali”}, {$set:{age:40}})
17. Update different customers with different ages from 20 to 40 (to be done on your own)
18. Set the gender for each customer accordingly (to be done on your own)
DELETE COMMANDS
19. Remove the first document with the first name Ali.
db.customers.deleteOne({first_name:"Ali"})
SEARCH COMMANDS
22. Find documents where last name is named Imran or first name is Siti using the
OR operator.
db.customers.find({$or:[{last_name:"Imran"},{first_name:"Siti"}]})
23. Find documents where last name is named Imran or first name is Siti using the
OR operator.
db.customers.find({$or:[{last_name:"Imran"},{first_name:"Siti"}]})
24. Find documents where age is greater than 30
db.customers.find({age:{$gt:30}});
26. Count the number of documents in collection customers that has male as gender.
db.customers.find({gender:”male”}).count();
27. Select the full name of customers where age is greater than 30
db.customers.find({age:{$gt:30}},{first_name:1, last_name:1})