Schema:
new Schema({
    productId: String,
    types: [{
        productType: String,
        lastModified: Date
    }]
});
Query:
{
  productId: "1",
  email: "test@test.com",
  productType: "test",
}
I tried this but its returning only first matched element:
const productType = 'test';
const result = await this.model(email)
.find(
    { productId, 'types.productType': productType },
    { 'types.$': productType }
).lean();
with aggregate, it return empty array result:
const result = await this.model(email).aggregate([
    { $match: { productId, 'types.productType': 'productType' } },
    {
        $project: {
            types: {
                $filter: {
                    input: '$types',
                    as: 'r',
                    cond: { $eq: ['$$r.productType', productType] }
                }
            },
            _id: 0
        }
    }
]);
I need to find all matching elements where projection $ returns the first matched
