您好,我想使用嵌入式填充
并在配方模型中保留成分数组
,但
在搜索一些网站时出现此错误,但找不到答案
throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
^
TypeError: Invalid schema configuration: `Ingredient` is not a valid type at path `ref`.
Run Code Online (Sandbox Code Playgroud)
在这里食谱模型,我添加了成分字段并给出了 objectId 类型和 ref 但代码在 ref 中给出了错误
const mongoose = require('mongoose');
const recipeSchema = new mongoose.Schema({
recipeName: {
type: String,
required: true,
min: 2,
max: 255,
},
addedUser: {
type: {
tpye: String,
required: true,
min: 2,
max: 255,
}
},
ingredients: [{
tpye: mongoose.Schema.Types.ObjectId,
ref: 'Ingredient'
}]
});
module.exports = mongoose.model('Recipe', …Run Code Online (Sandbox Code Playgroud)