Friday, 5 May 2017

OverwriteModelError: Cannot overwrite `Product` model once compiled

I have tried to call my productSchema in my purchaseSchema but I've got this error: OverwriteModelError: Cannot overwrite Product model once compiled. What can I try ?

It's my Schema of products:

mongoose = require('mongoose');
var Schema = mongoose.Schema;

var productSchema = new Schema({

cd: {
    type: Number,
    require: true
},

nm_iten: {
    type: String,
    require: true
},

type_iten: {
    type: String,
    require: true
},

unity: {
    type: String,
    require: true
},

});
var product = mongoose.model('Product',productSchema);
module.exports = {product:product}

And, it's my purchase Schema:

   var mongoose = require('mongoose');
   var Schema = mongoose.Schema;
   var productSchema = require('./products');
   var product = productSchema.product;

   var purchaseSchema = new Schema({

     code: {
       type: Number,
       require: true
    },

     product:[product],

     quant: {
       type: Number,
       require: true
    },

    vl_uni: {
       type: Number,
       require: true
     },

     vl_total: {
        type: Number,
        require: true
    }


    });
    mongoose.model('Purchase',purchaseSchema);



via Douglas Batista

No comments:

Post a Comment