[mongo-page查询示例] #mongodb #数据库
//聚合查询
let result = await this.ctx.model.Contract.aggregate([
{
$match: filter
},
{
$project: {tplContent: 0, content: 0}
},
{
$lookup: {
from: 'contract_attr',
localField: '_id',
foreignField: 'contractId',
as: 'items'
}
},
{
$lookup: {
from: 'admin_sign_queue',
localField: '_id',
foreignField: 'contractId',
as: 'adminSign'
}
},
{
$sort: { addTime: -1 }
},
{
$skip: (page - 1) * pageSize
},
{
//限制
$limit: pageSize
}
]);
//函数查询
let conList = await await this.ctx.model.Contract.find({
addTime: {
$gte: start,
$lte: end
}
}).sort({ 'addTime': -1 }).skip((page - 1) * pageSize).limit(pageSize);