Question : mongodb lookup with condition
Answered by : dhaval-italiya
var re = new RegExp("beg", "i"); let data = await accounts.aggregate([ { $match: { _id: mongoose.Types.ObjectId(req.params.userId), }, }, { $lookup: { from: "begs", localField: "_id", foreignField: "userId", as: "begCount", pipeline: [{ $match: { title: re } }], }, }, ]);
Source : | Last Update : Fri, 14 Oct 22