Mongoose query to list the document based on value from nested document Mongoose query to list the document based on value from nested document mongoose mongoose

Mongoose query to list the document based on value from nested document


It doesn't work this way because product_items.product_size evaluates to an array of objects and you are trying to compare a single object with such array. It is more reliable to use $elemMatch when working with arrays of objects:

db.collection.aggregate([    {        $match: {            "product_items": {                $elemMatch: {                    "product_size.value": 22,                    "product_size.unit": "ml"                }            }        }    }])

Mongo Playground