Error('The 2nd parameter to `mongoose.model() code example

Example: Error('The 2nd parameter to `mongoose.model()` should be a '

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var caseNote = mongoose.model('caseNote');
var ObjectId=mongoose.Schema.Types.ObjectId;
var models = require('./');
var autopopulate = require('mongoose-autopopulate');

var docSchema_raw = new Schema({
    decidingBody:{type:String},
},{discriminatorKey : '_type'});

var docSchema = caseNote.discriminator('doc',  docSchema_raw);

//DELETE THIS var doc = mongoose.model('doc',docSchema);
//USE this:

var doc = mongoose.model('doc');

exports.docSchema = docSchema;
module.exports = doc;


// Or if you already define a Schema avoid dupplicate defenition:
// keep this :
module.exports = mongoose.model("metadata_image_table", imageMetadataSchema);
// MUST BEEEE DELETE var Metadata = mongoose.model("metadata_image_table", imageMetadataSchema);