Mongo Version - v3.4
based on my last question - lookup with condition in mongoose
My query working on for page 1. but on the second page it gives empty result.
const casestudies = await CaseStudy.aggregate([{
$lookup: {
from: "categories",
localField: "category_id",
foreignField: "_id",
as: "category_id"
}
},
{
$project: {
"updated_at": 0,
"category_id.updated_at": 0
}
},
{
$lookup: {
from: "bookmarks",
localField: "_id",
foreignField: "type",
as: "bookmarks"
}
},
{
$addFields: {
bookmarks: {
$filter: {
input: "$bookmarks",
cond: { $eq: ["$$this.user_id", req.user ? objectId(req.user._id) : ''] }
}
}
}
},
{ $sort: { "publish_date": -1 } },
{ $limit: pageSize },
{ $skip: (page - 1) * pageSize }
]);
What's wrong in my query.
Please help me.
question from:
https://stackoverflow.com/questions/65558282/mongoose-query-with-pagination-not-working-properly 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…