wie man ein einzelnes Element von verschachtelten Array -Mongoose bekommt
//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