Database

[{"_id":1,"subject":{"subCode":"CSCI203","subTitle":"Algorithm and Data Structures","credit":3,"type":"Core","prerequisite":["csci103"],"assessments":[{"assessNum":1,"weight":10,"assessType":"Assignment","description":"Assignment 1 - Mathematic Concepts and Algorithm Complexity"},{"assignNum":2,"weight":15,"assessType":"Assignment","description":"Assignment 2 - Linear and Non-linear Data Structure"},{"assessNum":3,"weight":15,"assessType":"Assignment","description":"Assignment 3 - Greedy Algorithm and Branch-and-Bound"},{"assessNum":4,"weight":60,"assessType":"Examination","description":"Closed-book Final Examination"}],"book":[{"ISBN":"13:978-0-13-231681-1","bookType":"textbook","bookTitle":"Introduction to the Design and Analysis of Algorithms","edition":3,"yearPub":2012,"publisher":"Pearson","author":["Levitin"]},{"ISBN":"978-0-262-53305-8","bookType":"reference","bookTitle":"Introduction to Algorithms","edition":3,"yearPub":2013,"publisher":"The MIT Press","author":["Thomas H Cormen","Charles E Leiserson","Ronald L Riverst","Clifford Stein"]}]}},{"_id":2,"subject":{"subCode":"IACT201","subTitle":"Professional Practice and Ethics","credit":3,"type":"Elective","assessments":[{"assessNum":1,"weight":35,"assessType":"Assignment","description":"Assignment 1 - Ethical Dilemma Case Study"},{"assignNum":2,"weight":25,"assessType":"Presentation","description":"Presentation of Case Study"},{"assessNum":3,"weight":40,"assessType":"Examination","description":"Closed-book Final Examination"}]}},{"_id":3,"subject":{"subCode":"IACT201","subTitle":"Professional Practice and Ethics","credit":3,"type":"Electivedfdfdf","assessments":[{"assessNum":1,"weight":35,"assessType":"Assignment","description":"Assignment 1 - Ethical Dilemma Case Study"},{"assignNum":2,"weight":25,"assessType":"Presentation","description":"Presentation of Case Study"},{"assessNum":3,"weight":40,"assessType":"Examination","description":"Closed-book Final Examination"}]}}]

Query

db.collection.aggregate([{$match:{$or:[{"subject.type":"Core"},{"subject.type":"Elective"}]}},{$group:{_id:"$subject.type",count:{$sum:1}}}])

Result