Supposedly I want to get a an object from my collection, an to this object, I want to add a property that will store an array of object containing ids and title matching one of the property of my object (in my case series).
Example I have this object as a result from my initial query
{
_id: 13123123123,
title: "TitleofObject",
series: "SeriesName",
}
then I want to look on the same collection where the series name is the same for my object (add a new property named sameSeries to store objects matching the series) and the final result of object should look something like this
_id: 13123123123,
title: "TitleofObject",
series: "SeriesName",
sameSeries:
[
{
_id: 12312312,
title: "anothertitleofObject"
},
{
_id: 12312342312,
title: "anothertitleofObject2"
}
]
How can I achieve this using the aggregate method?
const book = await Book.aggregate([
{
$match: { _id: id }
},
])