node.js - 用快递分页
问题描述
我正在使用 mongoose & express 进行分页,这是代码
const page = req.query.page || 1;
const limit = 15;
const docs = await Model.find({
visibility: true,
$or: [{expires: {$gt: new Date().getTime()}}, {expires: null}]
})
.skip((page * limit) - limit)
.limit(limit);
这会导致错误(没有消息它只记录网络错误)但我知道问题的原因是这段代码,因为当我删除它时,它开始工作。什么是问题?
编辑
我将此代码更改为
Model.find({
visibility: true,
$or: [{expires: {$gt: new Date().getTime()}}, {expires: null}]
})
.skip(page * limit - limit)
.limit(15)
.exec((err,docs)=>{
if(err){
//handle err
}
res.status(200).send({
docs
})
})
它开始工作了。听起来不错,但我需要知道为什么它不能与 await 语法一起使用
解决方案
推荐阅读
- python-3.x - 为什么在 Tkinter 中创建小部件时,对象和方法之间需要一个空格?
- tomcat - 在 Tomcat 上部署 Eureka 客户端失败 - 无法启动 bean“eurekaAutoServiceRegistration”:没有为范围名称“刷新”注册范围
- android - 如何将数据绑定变量作为 xml 属性传递给自定义视图
- typescript - TypeScript 中的自定义 keyValue 类型
- c++ - 具有模板类型的函数的显式(完全)特化
- node.js - aws lambda 和 promise-mysql
- android - 如何更新 Firestore 中地图数组中的元素?
- github - 为什么查询对 sample_commits 有效,但对公共 github_repos 数据集中的提交无效?
- windows - 在将参数传递给 PS 文件时,如何使用 invoke-command 从 Windows 命令行运行 PS 文件?
- bash - 如何自动解决 git rebase 中的所有冲突,“git add .”