【发布时间】:2021-10-15 11:35:51
【问题描述】:
我为我的模型创建了一个接口,我只想从记录中返回特定数据
// code.interface.ts
import { Document } from 'mongoose';
export interface CodeI extends Document {
readonly _id: string;
readonly logs: any;
}
但是当我从 mongo 获得结果时,它完全忽略了我界面中的内容。 (我使用 NestJs 作为框架)
//constructor
constructor(@InjectModel(Coupon.name) private couponModel: Model<CouponDocument>) {}
// function
async findOne(codeId: string): Promise<CodeI> {
const coupon = await this.couponModel.findOne({ _id: codeId }).exec();
if (!coupon) {
throw new NotFoundException([`#${codeId} not found`]);
}
return coupon;
}
【问题讨论】:
标签: node.js typescript mongoose nestjs