In my collection, I am referring field as an array of object(skill and year are the keys ) in which one field in that object refers to another collection
primary_skills: [
{
skill_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Skill'
},
years: Number
}
],
What I want to achieve to list all skills
profile.aggregate([{
$lookup:{
from:'skills',
localField:'primary_skills.skill_id',
foreignField:'_id',
'as':'primary_skills'
}
}])
This works fine but the year
key in the object is missing while running this
Output:
"primary_skills": [
{
"_id": "5f0d885307a96c3040b3667b",
"name": "PHP",
"__v": 0
}
]
Expected output:
"primary_skills": [
{
"name": "PHP",
"Years":"12"
}
]