Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 架构配置无效:`…`在路径`ref处不是有效的类型`_Node.js_Mongodb_Mongoose - Fatal编程技术网

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岁的孩子,这条评论救了我一命