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);
your "type" in "ingredients:" and "addedUser:" in controller and its writed as "tpye". try to change that!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With