const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017';
// Database Name
const dbName = 'youyue';
var obj = {};
module.exports = async(ctx,next)=>{
const num = ctx.query.num,
page = ctx.query.page,
sort = ctx.query.sort;
num = isNaN(num)? 10 : parseFloat(ctx.query.num)
page = isNaN(page)?0 : parseFloat(ctx.query.page)
sort = isNaN(sort)?-1 : parseFloat(ctx.query.sort)
console.log(num+"*"+sort+"*"+page);
MongoClient.connect(url, function (err, client) {
const db = client.db(dbName);
const collection = db.collection('site');
collection.find().sort({ id: sort }).skip(num*page).limit(num).toArray(function (err, Database){
console.log(Database);
//目标数据
obj.result = Database;
});
});
await next();
//填充数据到页面
ctx.body = obj.result;
}
慕斯王
慕姐8265434
相关分类