Use the coffee
database on the cpsc server’s Mongo
instance for this assignment. Answer the following questions with both a
query and the actual answer:
db.shops.countDocuments()
30
db.shops.distinct("city",{},{'city':1})
[ 'Boston', 'Chicago', 'Portland', 'San Francisco', 'Seattle' ]
db.shops.distinct("city",{wifi_quality:'Excellent'},{'city':1})
[ 'Boston', 'Chicago', 'San Francisco' ]
db.shops.distinct("name",{$or:[{'city':'Boston'},{'city':'Seattle'}], 'rating':{'$gt':4.5}}, {'name':1,'_id':0})
[ 'Java Jive', 'Mocha Motion' ]
db.shops.aggregate([{'$group':{'_id':null,'avgrating':{'$avg':'$rating'}}}])
[ { _id: null, avgrating: 4.346666666666667 } ]
db.shops.aggregate([{$unwind:'$menu'},{$match:{'menu.item':'Cold Brew'}}, {'$group':{'_id':null,'avgRating':{'$avg':'$rating'}}}])
[ { _id: null, avgRating: 4.32 } ]
db.shops.aggregate([{$group:{'_id':'$city', 'count':{'$sum':1}}}, {$project:{'count':1,'city':'$_id','_id':0}}, {'$sort':{'count':-1}}])
[
{ count: 14, city: 'Chicago' },
{ count: 6, city: 'Seattle' },
{ count: 4, city: 'Portland' },
{ count: 4, city: 'Boston' },
{ count: 2, city: 'San Francisco' }
]