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;
}