我在mongoose中创建了一个Schema,当我启动node时,它崩溃了
const mongoose = require("mongoose");
const { DataView } = require("webidl-conversions");
const productSchema = new mongoose.Schema({
name:{
type:String,
required:[true,"Please Enter Product Name"],
trim:true
},
description:{
type:String,
required:[true,"Please Enter Product Description"]
},
price:{
type:Number,
required:[true,"Please Enter Product Price"],
maxLength:[6,"Price cannot exceed 6 characters"]
},
rating:{
type:Number,
default:0
},
images:[
{
public_id:{
type:String,
required:true,
},
url:{
type:String,
required:true,
}
}
],
category:{
category:String,
required:[true,"Please Enter Product Category"],
},
stock:{
type:Number,
required:[true,"Please Enter Product Stock"],
maxLength:[4,"stock cannot excee 4 characters"],
default:1
},
numOfReviews:{
type:Number,
default:0
},
reviews:[
{
name:{
type:String,
required:true,
},
rating:{
type:Number,
required:true,
},
comment:{
type:String,
required:true,
}
}
],
createdAt:{
type:Date,
default:Date.now
}
})
mosule.export = mongoose.model("Product",productSchema);
这是我的schema代码,我得到TypeError:无效的架构配置:无法确定数组category.required
的嵌入类型。请参阅https://mongoosejs.com/docs/guide.html#definition了解更多关于支持的模式语法的信息此错误我不知道是什么问题,所以请帮助我,提前感谢
2条答案
按热度按时间irlmq6kh1#
基于我在这里看到的,似乎你导出模块的方式是一个给你的问题。
将
module.exports
改为mosule.export
快看
qyswt5oh2#
如果你想要一个类别数组,那么你可以用这个