Jak uzyskać pojedynczy element z zagnieżdżonej tablicy 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]
Liz