【发布时间】:2021-07-05 07:26:13
【问题描述】:
我有这个查询要显示在前端的表格中,所以我使用了工作正常的分页
tableSchema.statics.getn = (query, options) => {
return mongoose.model(MODEL_NAME).paginate(query, options);
};
但是当我尝试执行搜索查询时,我无法对其执行分页。有没有办法将响应作为分页形式发送到所有搜索到的查询 我尝试了以下代码
tableSchema.statics.search = query => {
const Id = Number(query);
const isNumeric = value => /^\d+$/.test(value);
if (!isNumeric(query)) {
if (query.includes("@")) {
const regex = new RegExp(query, "i");
return mongoose.model(MODEL_NAME).find({ "recipies.to": regex }).paginate(query);
}
return mongoose.model(MODEL_NAME).find({ "temp.name": query });
}
return mongoose.model(MODEL_NAME).find({ recipies: { Id } });
};
分页不是一个函数,这给我带来了错误。我尝试将查找查询结果存储在对象中,然后执行分页仍然无法正常工作。
我正在使用“mongoose-paginate-v2”进行分页
【问题讨论】:
标签: node.js mongodb mongoose pagination mongoose-schema