How can i combine multiple collection into one collection using with $lookup mongodb or nodejs mongodb?

拈花ヽ惹草 提交于 2019-11-29 18:52:27

You should use $skip and $limit to avoid this error. why getting this error ? you have to read @Alex comment link.

db.products.aggregate([ 
    {$skip:0},{$limit: 1000},
    {$lookup:{from:"productgroups", localField:"productgroupid", foreignField:"productgroupid", as:"group"}},
    {$lookup:{from:"category", localField:"categoryid", foreignField:"categoryid", as:"category"}},
    {$lookup:{from:"divisions", localField:"divisionid", foreignField:"divisionid", as:"division"}},
    {$project: {productpoint:1,productname:1,productcode:1,productid:1,group: { $arrayElemAt: [ "$group", 0 ]},
                category: { $arrayElemAt: [ "$category", 0 ]}, division: { $arrayElemAt: [ "$division", 0 ]} }} 
  ]);

{$skip:0},{$limit: 1000}// for initial and then for next time should skip: 1000, limit:1000 and so on. you may get it from request or by using loop or as you implement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!