You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Mongoose与MongoDB聚合查询时遭遇错误码5107201的问题求助

使用Mongoose与MongoDB聚合查询时遭遇错误码5107201的问题求助

大家好,我在使用Mongoose配合MongoDB执行聚合查询时遇到了一个棘手的错误,错误码是5107201,自己排查了好一阵都没找到原因,特意来这里求助!

错误信息

{
  "error": {
    "ok": 0,
    "code": 5107201,
    "codeName": "Location5107201",
    "$clusterTime": {
      "clusterTime": {
        "$timestamp": "7292060947630260235"
      },
      "signature": {
        "hash": "HQW2T+0z31Kf8q6iLViqdu0uYtQ=",
        "keyId": {
          "low": 2,
          "high": 1683641553,
          "unsigned": false
        }
      }
    },
    "operationTime": {
      "$timestamp": "7292060947630260235"
    }
  }
}

我的代码逻辑

我正在做一个评论列表的查询功能,需要关联users和products集合,同时支持分页和动态排序。具体代码如下:

let page = 1;
let limit = 10;
let sort = {};
let skip = (page-1)*limit

// req.query.sort 传入的值为 'name' 或者 '-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: skip },
  { $limit: limit },
]);

我检查过filter的正确性,也确认了关联集合的字段映射没有问题,分页和排序的逻辑看起来也符合预期,但就是触发了这个5107201错误。有没有大佬遇到过类似的问题,或者能帮我指出代码里可能存在的问题?

备注:内容来源于stack exchange,提问作者Donisher Djumaqulov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 10:28:10