“错误”:{“ok”:0,“code”:5107201,“codeName”:“Location5107201”,“$clusterTime”:{“clusterTime”:{“$timestamp”:“7292060947630260235”},“signature”:{“hash”:“HQW2T+0z31Kf8q6iLViqdu0uYtQ=",“keyId”:{“low”:2,“high”:1683641553,“unsigned”:© 2019 www.szb.com版权所有并保留所有权利
let page = 1;
let limit = 10;
let sort = {};
let skip =(page-1)*limit
//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: skip },
{ $limit: limit },
]);
字符串
1条答案
按热度按时间yhived7q1#
问题是page和limit都是String
字符串