I have the the following selection query in MongoDb. I want to console log the return of the query.
student.findCourses = (fcallback) => {
global.db.collection('students').find(({}, { "courses.courseName": true, _id: false }).toArray, (err, result) => {
if (err) {
var jError = { "status": "error", "message": "ERROR -> student.js -> 001" }
console.log(jError)
return fcallback(true, jError)
}
var jOk = { "status": "ok", "message": "student.js -> found -> 000" }
var jResult = ????
console.log(jOk)
return fcallback(false, jOk)
})
}
Simply I want to see the following in the console.log. And not by manually defining it. I want that it comes directly from the db.
Is there a way to do this?
{
"courses": [
{
"courseName": "Web-development"
},
{
"courseName": "Databases"
},
{
"courseName": "Databases"
}
]
}