【发布时间】:2020-03-06 12:51:34
【问题描述】:
我有以下 Mongoose 模型架构。我正在使用打字稿文件。
// Core Modules
// NPM Modules
import mongoose from "mongoose";
import slugify from "slugify";
// Custom Modules
const CategorySchema = new mongoose.Schema({
name: {
type: String,
required: [true, "Please add a Category Name"],
unique: true,
trim: true
},
slug: {
type: String,
unique: true
},
description: {
type: String,
required: [true, "Please add a description"],
maxlength: [500, "Description can not be more than 500 characters"]
}
});
// Create bootcamp slug from the name
CategorySchema.pre("save", function(next) {
this.slug = slugify(this.name, { lower: true });
next();
});
module.exports = mongoose.model("Category", CategorySchema);
我收到以下错误
“文档”类型上不存在任何属性“slug”.ts(2339)
“文档”类型上不存在任何属性“名称”.ts(2339)
【问题讨论】:
标签: typescript mongoose mongoose-schema