Mongoose Schema hasn't been registered for model

前端 未结 17 881
猫巷女王i
猫巷女王i 2020-11-27 15:00

I\'m learning the mean stack and when I try to start the server using

npm start

I get an exception saying that:

schema has         


        
17条回答
  •  感情败类
    2020-11-27 15:39

    Elaborating on Rafael Grilli's answer above,

    Correct:

    var HouseSchema = new mongoose.Schema({
      date: {type: Date, default:Date.now},
      floorplan: String,
      name:String,
      house_id:String,
      addressLine1:String,
      addressLine2:String,
      city:String,
      postCode:String,
      _locks:[{type: Schema.Types.ObjectId, ref: 'xxx'}] //ref here refers to the first parameter passed into mongoose.model()
    });
    var House = mongoose.model('xxx', HouseSchema, 'houseschemas');
    

提交回复
热议问题