TypeError:无效架构配置:' model '不是数组' category '中的有效类型 &



我有两个模式:Item和Category。我想在项目中使用类别,我如何合并它们?下面是代码:

类别:

const mongoose = require('mongoose');
const categorySchema = mongoose.Schema({
name: {type: String, required: true},
description: {type: String, required: true},
city: {type: String, required: true},
});
var categoryData = mongoose.model("categoryData", categorySchema);
module.exports = categoryData;

单品:

const mongoose = require('mongoose');
const categSchema = require("./category.js")
const itemSchema = mongoose.Schema({
name: {type: String, required: true},
created: {type: Date, required: true, unique: true},
category: [categSchema],
quantity: {type: Number, required: true}
});
var itemData = mongoose.model("itemData", itemSchema);
module.exports = itemData;

我得到的错误是"TypeError: Invalid schema configuration:model不是数组category中的有效类型">

我做错了什么?

代替module.exports=categoryData

执行以下操作:

module.exports = categorySchema.

相关内容

  • 没有找到相关文章

最新更新