skip to Main Content

Missing Schema Error: Schema hasn’t been registered for model "[object Object]".
Use mongoose model(name, schema)
at Mongoose model
error occurred

need solution for this problem

2

Answers


  1. Chosen as BEST ANSWER
    const mongoose=require('mongoose')
    var Schema = mongoose.Schema
    
    
    const productSchema=new Schema({ 
        name:{
            type:String,
            required:[true, "please enter product name"]
        },
        description:{
            type: String,
            required:[true, "please enter product Description"]
        },
     created At:{
           type: Date,
           default: Date. now
        }
    })
    module. exports=mongoose. model("product", product Schema)
    
    

    After Mongoose. model() put model Name and then Schema

    hoping you Got The Solution


  2. in ./src/models/channel.js file:

    const { Schema, model } = require("mongoose");
    
    // Discord' channel model
    const channelSchema = new Schema({
      identifier: { type: String, required: true    },
      message:    { type: String, default: "ping !" },
      guild:      { type: String, required: true    },
      type:       { type: String, required: true    },
      mode:       { type: Boolean                   }
    });
    
    module.exports = model("Channel", channelSchema);
    

    in other files:

    const Channel = require("../models/channel");
    
    const toto = await Channel.create({
      identifier: 1,
      guild: "toto",
      type: "tata",
    });
    console.log(toto);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search