为什么搜索state为1时候返回结果为空数组

来源:7-11 用户新增接口实现

慕雪9296518

2021-06-16

当我搜索state = 0或者state = 2时候,都可以返回正确结果,但是搜索条件state = 1时候就返回为空,为什么呀
async Simplefind(ctx,next){
const { per_page = 10, username, userId, state } = ctx.query
const page = Math.max(ctx.query.page * 1,1) - 1;
const prePage = Math.max(per_page * 1,1);
let params = {}
if (userId) params.userId = userId;
if (username) params.username = username;
if (state && state != 0) params.state = state;
const list = await User.find(params).limit(prePage).skip(page*prePage).sort({userId:1})
//const query = User.find(params, { _id: 0, userPwd: 0 })
//表示搜索结果去除了_id和密码
const total = await User.countDocuments(params);
const totalpage = Math.ceil (total / prePage)
ctx.body = {list,total,totalpage,code:200}
}

写回答

1回答

河畔一角

2021-06-18

数据库有状态为1的数据吗?

0
0

Vue3+ElementPlus+Koa2 全栈开发后台系统

从前端晋级到全栈,让你的未来发展有更多可能

1069 学习 · 580 问题

查看课程