how to get single element from nested array mongoose
//This solution isn't very elegant, but it works. const objectInNestedArray = (await Schema.findOne({ _id: '62a5bc408a97563a666c63dd', nestedArray : { $elemMatch : { _id: new mongoose.Types.ObjectId(id) }}//must be ObjectId }, { nestedArray: { "$filter": { "input": "$nestedArray", "as": "objectInNestedArray", "cond": { "$eq": ["$$objectInNestedArray._id", new mongoose.Types.ObjectId(id)] } //must be ObjectId } } }))['nestedArray'][0]
Query nested array of objects in mongoose
db.collection.find({ "instock.items": { $elemMatch: { name: "alexa" } } })
Source: stackoverflow.com