I have a Schema
_id:"5ff9b57d2c196236206a0e96"
eventId:"1"
eventName:"Name"
teams:[
0: {player:"5245552555556"}
1: {player:"5245552559557"}
2: null
]
Expected result should be like
_id:"5ff9b57d2c196236206a0e96"
eventName:"Name"
teams:[
0: {player: {
firstName : "player1"
lastName : "player1"
email : "player1@email.com"
}
1: {player: {
firstName : "player2"
lastName : "player2"
email : "player2@email.com"
}
}
]
I am running the below query to get the result but if it finds any null value it doesn't return that whole document instead what I need is just to ignore that particular field with null value and populate the rest of the fields
const teams = await Event.find({_id:eventId },{"teams":{$ne:null"} }).populate(
"teams.player",
"firstName lastName email "
);