【发布时间】:2021-08-31 22:34:16
【问题描述】:
我正在使用 Mongoose 创建一个 NestJs 应用程序,我目前在尝试访问 createdAt 时遇到问题,即使我已将时间戳设置为 true,我的代码如下。
product.schema.ts
@Schema({timestamps: true})
export class Product extends Document {
@Prop({ required: true })
name!: string;
}
product.service.ts
public async getProduct(name: string): Promise<void> {
const existingProduct = await this.productModel.findOne({ name });
if (!existingProduct) {
throw new NotFoundException();
}
existingProduct.createdAt //Property 'createdAt' does not exist on type 'Product'
}
【问题讨论】:
标签: typescript mongodb express mongoose nestjs