1) For the Mongo DB statements / commands, explain what the output would be. (whatsapp/ 00966559712545)
• Using a new command prompt, we type C:\Users\Uma Radhakrishnan> cd c:\Program Files\MongoDB\Server\5.0\bin
C:\Program Files\MongoDB\Server\5.0\bin> mongod –dbpath F:mongodb5\data\db
What are you achieving by this command?
• Using a new command prompt page, we type C:\Users\Uma Radhakrishnan>cd C:\Program Files\MongoDB\Server\5.0\bin
C:\Program Files\MongoDB\Server\5.0\bin>mongo
What are you achieving by this command?
• We type> use myoldstudents
What are you achieving by this command?
• We type >
db.myusers.insertMany([{“name”:”steve”,”profession”:”cricket”,age:44},{“name”:”john”,”hobby”:”fielding”,age:61″,”date_join”:”2020-11-01″ }])
What is the name of the collections?
What are you achieving by this command?
• We type > db.myusers.find({age:{$lt:50}})
What are you achieving by this command?
• We type > db.myusers.updateMany({age:{$gt:40}},{$set:{“category”:”player”}})
What are you achieving by this command?
• We type > db.myusers.findAndModify({query:{“name”:”steve”},update:{$inc:{age:5}}})
What are you achieving by this command?
What will be the output?
• We type > db.myusers.findAndModify({query:{“name”:”steve”},update:{$inc:{age:5}}})
Then, we type, > db.myusers.find().pretty()
What will be the output?
• We type > db.myusers.find({date_join: {$lt: “2020-12-01”}}).pretty()
What will be the output?
• We type > db.purchaseorders.insertMany([{“pdt”:”water”,total:5.75,”customer”:”mike”},{“pdt”:”coke”,total:14.75,”customer”:”john”},{“pdt”:”rice”,total:24.75,”customer”:”asha”},{“pdt”:”water”,total:5.75,”customer”:”peter”},{“pdt”:”milk”,total:4.75,”customer”:”mike”}])
Then we type, > db.purchaseorders.aggregate([{$match:{}},{$group:{_id:”$customer”,total:{$sum:”$total”}}}])
What will be the output?
• What is the fundamental difference between MYSQL database and MongoDB database?
• Why are we not writing joins in MongoDB database?
Sample Solution