Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 359 Bytes

mongoose-join-query.md

File metadata and controls

26 lines (23 loc) · 359 Bytes
return await TestModel.aggregate([
  {
    $lookup: {
      from: "customers",
      localField: "customer",
      foreignField: "_id",
      as: "customer",
    },
  },
  {
    $match: QueryData,
  },
  { $unwind: "$customer" },

  {
    $sort: {
      createdAt: -1,
    },
  },{
    $limit:5
  }

]);