在我的 Api 中使用聚合 mongoose mongoDb 后出现错误

问题描述 投票:0回答:1

“错误”:{ “好的”:0, “代码”:5107201, "代号": "位置5107201", “$clusterTime”:{ “集群时间”:{ “$时间戳”:“7292060947630260235” }, “签名”: { “哈希”:“HQW2T + 0z31Kf8q6iLViqdu0uYtQ =”, “密钥ID”:{ “低”:2, “高”:1683641553, “未签名”:假 } } }, “操作时间”:{ “$时间戳”:“7292060947630260235” } }

let page = 1;
let limit = 10;
let sort = {};
//req.query.sort is coming as 'name' or '-name'
  if (req.query.sort) {
     const key = req.query.sort;
     if (req.query.sort[0] === "-") {
        sort[`${key.substring(1)}`] = -1;
        sort["_id"] = 1;
     } else {
        sort[`${key}`] = 1;
        sort["_id"] = 1;
     }
  } else {
     sort.dateCreated = 1;
  }

const reviewsList = await Review.aggregate([
     { $match: filter },
     {
        $lookup: {
           from: "users",
           localField: "user",
           foreignField: "_id",
           as: "user",
        },
     },
     {
        $unwind: "$user",
     },
     {
        $lookup: {
           from: "products",
           localField: "product",
           foreignField: "_id",
           as: "product",
        },
     },
     {
        $unwind: "$product",
     },
     {
        $sort: sort,
     },
     { $skip: (page-1)*limit },
     { $limit: limit },
  ]);

mongodb mongoose aggregate
1个回答
0
投票

问题是页面和限制是字符串

const ReviewsList = 等待 Review.aggregate([ ………… { $skip: +skip }, {$限制:+限制}, ]);

© www.soinside.com 2019 - 2024. All rights reserved.