This is a two part mongoDB/mongoose question
I want to concat a First Name/Last Name into "name" AND I only want to show the single "current" item from an array.
So if my data looks like this
[{
"fname":"bob",
"lname":"jones",
"role":"professional",
"active":true,
"jobs":[{
"job":"janitor",
"current":true
},{
"job":"dog groomer"
"current":false
}]
},{
"fname":"sally",
"lname":"peterson",
"role":"professional",
"active":true,
"jobs":[{
"job":"engineer",
"current":false
},{
"job":"college admin"
"current":true
}]
},{
"fname":"jackson",
"lname":"smiley",
"role":"professional",
"active":true,
"jobs":[{
"job":"car salesman",
"current":false
},{
"job":"street sweeper"
"current":false
}{
"job":"house painter"
"current":true
}]
},{
"fname":"katie",
"lname":"smiley",
"role":"amature",
"active":true,
"jobs":[{
"job":"drone entheuast",
"current":true
}]
}]
And I want my return data to be
[{
name:"bob jones",
job:"janitor"
},{
name:"sally peterson",
job:"college admin"},
{
name:"jackson smiley",
job:"house painter"
}]
Currently - I am using this mongoose syntax - but it's not enough...
module.exports.getActiveList = function( callback ) {
const query = { "role":"professional", "active":true }
People.find( query, 'name job', callback );
}
How would I do that?