



理想是火,点燃熄灭的灯。
生成随机数的优化 269
Node.js中使用Lodash 345
git操作日常记录学习 307
百度翻译api调试 386
消息推送 - uni-push的配置和开通 687
uni-app小程序开发记录 479


废话不多说,这个就是为了实现 文章的上一篇和下一篇的接口
直接上代码:
router.post("/bookInfo", async (ctx) => {
let bookId = ctx.request.body.ID;
const book = mongoose.model("book");
// 获取上一篇和下一篇的文章
// select是指定返回的字段
let prevBook = await book
.findOne({ ID: { $lt: bookId }, visible: true })
.sort({ ID: -1 })
.select({ ID: 1, title: 1 })
.then((res) => res);
let nextBook = await book
.findOne({ ID: { $gt: bookId }, visible: true })
.sort({ ID: 1 })
.select({ ID: 1, title: 1 })
.then((res) => res);
await book
.findOne({ ID: bookId })
.exec()
.then((res) => {
ctx.body = { code: 200, message: res, prevBook, nextBook };
})
.catch((err) => {
ctx.body = { code: 500, message: err };
});
});
参考:https://blog.csdn.net/u012914342/article/details/113518097
$ne的使用:
在find的条件中 不匹配某个结果
let boardMsgLength = await messageBoard.find({ from: "留言板" }).count(); //匹配留言板的数量
let booksMsgLength = await messageBoard // 匹配非留言板的数量 且 根据ID查询
.find({ from: { $ne: "留言板" }, ID: MessageBoardId })
.count();
作者: Bill 本文地址: http://biaoblog.cn/info?id=1649235037880
版权声明: 本文为原创文章,版权归 biaoblog 个人博客 所有,欢迎分享本文,转载请保留出处,谢谢!
上一篇:ssh学习随笔记录