I am having issues with $aggregate with mongoose. I am using $lookup to get the document from the raps table, but as the size of the raps documents with matching userId is huge it fails every time.
errmsg: 'Total size of documents in raps matching { $match: { $and: [ { owner._id: { $eq: "ID" } }, {} ] } } exceeds maximum document size', code: 4568
I have tried with allowDiskUse and it didn't work also tried $out and adding it into temp table, didn't work either.
I have also tried using $unwind after the $lookup as mentioned in one of the answer, but it doesn't seem to work.
I have the following snippet.
userAccountModel.aggregate([
{
$match:
{
_id: userId
}
},
{
$lookup: {
from: "raps",
localField: "_id",
foreignField: "owner._id",
as: "rapsDocs"
}
},
{
$project : {
"likes": { $sum: "$rapsDocs.likes" }
}
}
]).allowDiskUse(true).exec(function(err, result){
})