3

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){
})
Ketan Saresa
  • 109
  • 1
  • 6
  • 1
    Possible duplicate of [Aggregate $lookup Total size of documents in matching pipeline exceeds maximum document size](https://stackoverflow.com/questions/45724785/aggregate-lookup-total-size-of-documents-in-matching-pipeline-exceeds-maximum-d) – mickl Jan 11 '18 at 18:30
  • I have tried that solution, but doesn't seem to work.. – Ketan Saresa Jan 11 '18 at 18:35
  • Where you using this in the Node MongoDB module? I am able to get my query working directly in shell (Mongo 3.4) but when running it with the node module I still get the maximum doc size error - exact same query – nwkeeley Dec 13 '18 at 21:24

0 Answers0