I was able to get past last week with the help of another discussion thread, but I wanted to understand further.
What is the difference between the following pipelines other than that the first one is incorrect? What are they doing differently?
[
{
$lookup: {
from: 'comments',
localField: '_id',
foreignField: 'movie_id',
as: 'comments'
}
},
{
$sort: { 'comments.date': -1 }
}
]
and
[
{
$lookup: {
from: 'comments',
let: {
id: '$_id'
},
pipeline: [{
$match: {
$expr: {
$eq: [
$movie_id, '$$id'
]
}
}
},
{
$sort: {
date: -1
}
}
],
as: 'comments'
},
}
]
Thanks!