result = db.student.find({}, { "fname": 1, "lname":1, "_id": 0 } ).toArray() // May not always work as toArray() returns a promise, // which may not be ready for use. result.forEach((x,i) => console.log('student #' + String(i) + ': ' + x["fname"] + ' ' + x["lname"])) // Show the names and credits (ach) of students majoring in 'CSCI' and having 40 or more credits. db.student.find( { "major": "CSCI", "ach" : {$gte: 40} }, { "fname": 1, "lname":1, "major": 1, "ach":1, "_id": 0 } ) // Show the first name and last name of students with a first name starting with a L or B, case insensitive. db.student.find( { "fname": { $regex: /^[lb]/, $options: "i" } }, { "fname": 1, "lname":1, "_id": 0 } ) // Show the names and credits (ach) of students majoring in 'CSCI' and having 40 or more credits. db.student.find( { "$and": [ { "major": "CSCI"}, { "ach": {"$gte": 40}} ] }, // query: vs. SQL: WHERE major = 'CSCI' AND ach >= 40 { "fname": 1, "lname":1, "ach":1, "_id": 0 } ) // a sequence of steps defined by the list [], first argument. db.faculty.aggregate([ {"$group" : {_id:"$deptCode", "count":{$sum:1}}} ]) db.faculty.aggregate([ {"$group" : {_id:"deptCode", "count":{$sum:1}}} ]) // pipeline: step i's output become step (i+1)'s input db.faculty.aggregate( [ { $group: { "_id": "$deptCode", "count": {$sum:1}} }, { $project: { "deptCode": "$_id" , "num_faculty": "$count", "_id": 0}} ] ) db.enroll.find( {"grade": "B+"}, {"_id": 0, "classId": 1, "stuId":1, "grade":1} )