Node.js 架构配置无效:`…`在路径`ref处不是有效的类型`
您好,我想使用嵌入式填充Node.js 架构配置无效:`…`在路径`ref处不是有效的类型`,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,您好,我想使用嵌入式填充 并将配料数组保留在配方模型中 但是出现了这个错误 搜索一些网站,但找不到答案 throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` + ^ TypeError: Invalid schema configuration: `Ingredient` is not a valid type at path `ref`. 在配方模型中,我添加了配料字段,并给出了o
并将配料数组保留在配方模型中
但是出现了这个错误
搜索一些网站,但找不到答案
throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
^
TypeError: Invalid schema configuration: `Ingredient` is not a valid type at path `ref`.
在配方模型中,我添加了配料字段,并给出了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', recipeSchema);
成分模型
const mongoose = require('mongoose');
const ingredientSchema = new mongoose.Schema({
ingredientName: {
type: String,
required: true,
min: 2,
max: 255,
},
quantity: {
type: {
tpye: Number,
required: true,
min: 0
}
},
unit: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Unit'
}
});
module.exports = mongoose.model('Ingredient', ingredientSchema);
您的“输入”在控制器中的“成分:”和“加法器:”中,并将其写为“tpye”。试着改变这一点 schema.OMG中拼写错误的类型我怎么没看到呢?非常感谢@Gibbs3岁的孩子,这条评论救了我一命