Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid schema configuration: `...` is not a valid type at path `ref`

Hello I want to use embedded populate
and keep ingredient array in recipe model
but got this error
search some sites but couldn't find answer

    throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
    ^

TypeError: Invalid schema configuration: `Ingredient` is not a valid type at path `ref`. 

here Recipe Model, I added ingredients field and give objectId type and ref but code give error in 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);

Ingredient Model

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);
like image 247
ocavo Avatar asked Oct 23 '25 18:10

ocavo


1 Answers

your "type" in "ingredients:" and "addedUser:" in controller and its writed as "tpye". try to change that!

like image 154
daniel mendes Avatar answered Oct 26 '25 10:10

daniel mendes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!