MongoDB aggregation: Counting results of the lookup without joining
I'm working with this query: customers.aggregate: [ {$lookup: { from: "users", localField: "_id", foreignField: "customerId", as: "users" }}, {$lookup: { from: "templates", let: {localField: "$_id"}, pipeline: [{ $match: { $and: [{ $expr: { $eq: ["$customerId", "$$localField"]}}, {module: false}] }}], as:…