Question : aggregation in mongoDB
Answered by : dhaval-italiya
{"tags":[{"tag":"textarea","content":"let videos= await Beg.aggregate([\n {\n $project: { \/\/ allows you to select or unselect filed.\n _id: 1,\/\/_id: 1 will select the field and _id: 0 will unselect field \n },\n },\n {\n $lookup: {\n from: \"videos\", \/\/the sub table or document\n localField: \"_id\", \/\/ filed name of main table or doc\n foreignField: \"begId\", \/\/ filed name of sub table or doc\n as: \"videos\", \/\/ name your object\n },\n },\n ]);","code_language":"whatever"}]}
Source : | Last Update : Fri, 03 Feb 23