作品列表接口传参isTemplate后查不出数据的问题
关于作品列表接口传参isTemplate后查不出数据的问题
问题描述:
api/works
相关截图:
不传isTemplate时有数据

传入isTemplate后查不出数据,但是用mogo命令行去查还是能查出来

相关代码:
数据库mogo版本:4.4.6
controller层代码跟视频一致的
async myList() {
const { ctx } = this
const userId = ctx.state.user._id
const { pageIndex, pageSize, isTemplate, title } = ctx.query
const findConditon = {
user: userId,
...(title && { title: { $regex: title, $options: 'i' } }),
...(isTemplate && { isTemplate: !!parseInt(isTemplate) }),
}
console.log(findConditon)
const listCondition: IndexCondition = {
select: 'id author copiedCount coverImg desc title user isHot createdAt',
populate: { path: 'user', select: 'username nickName picture' },
find: findConditon,
...(pageIndex && { pageIndex: parseInt(pageIndex) }),
...(pageSize && { pageSize: parseInt(pageSize) }),
}
const res = await ctx.service.work.getList(listCondition)
ctx.helper.success({ ctx, res })
}model层由于版本问题修改了下api调用方式,不知道是不是版本造成的
function initWorkModel(app: Application) {
const mongoose = app.mongoose
const Schema = mongoose.Schema
const AutoIncrement = AutoIncrementFactory(mongoose)
const WorkSchema = new Schema<WorkProps>(
{
uuid: { type: String, unique: true },
title: { type: String, required: true },
desc: { type: String },
coverImg: { type: String },
content: { type: Object },
isTemplate: { type: Boolean },
isPublic: { type: Boolean },
isHot: { type: Boolean },
author: { type: String, required: true },
copiedCount: { type: Number, default: 0 },
status: { type: Number, default: 1 },
user: { type: Schema.Types.ObjectId, ref: 'User' },
channels: { type: Array },
latestPublishAt: { type: Date },
},
{ timestamps: true },
)
WorkSchema.plugin(AutoIncrement, { inc_field: 'id', id: 'works_id_counter' })
return mongoose.model<WorkProps>('Work', WorkSchema)
}请老师解答。
11
收起
正在回答 回答被采纳积分+1
3回答



恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星