I want to get some objects from array of objects in a mongodb document my document looks something like this
{
movieDetails: {
movieId: 333,
movieName: "movie",
},
Dates: [
{
Date: " 01/07/2021",
TheaterId: 12,
Is3D: "false",
},
{
Date: " 09/07/2021",
TheaterId: 13,
Is3D: "false",
},
{
Date: " 03/07/2021",
TheaterId: 12,
Is3D: "false",
}
]
}
I want to get only the objects where the movieId is equal to 333 and TheaterId is 12 my result should look like this
[
{
Date: " 01/07/2021",
TheaterId: 12,
Is3D: "false",
},
{
Date: " 03/07/2021",
TheaterId: 12,
Is3D: "false",
}
]
I tried this
const dates = await Movie.find("movieDetails.movieId": 333).select({ Dates: {$elemMatch: {TheaterId: 12}}});
But it returns only the first object if anyone can help me with this I will be very grateful