router.get("/randomBooks", async (ctx) => {
console.log("????");
const book = mongoose.model("book");
await book
.aggregate()
.project({ ID: 1, img: 1, date: 1, reads: 1, title: 1 })
.match({})
.sample(6)
.then((res) => {
ctx.body = {
code: 200,
message: res,
};
})
.catch((err) => {
ctx.body = { code: 500, message: err };
});
});
await book
.find(
{ visible: true },
{ ID: 1, date: 1, img: 1, reads: 1, summary: 1, tag: 1, title: 1 }
)