I came across something strange. I have several mongoose models - and in one of them (only one!) I get this error:
TypeError: Schema is not a constructor
It’s very strange for me, because I have several workflows. I tried writing mongoose.Schemato a non-working scheme and it really differs from mongoose.Schema in my working schemes - how is this possible? The code is almost identical. Here is the code for the inoperative circuit:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var errSchema = new Schema({
name: String,
images:[{
type:String
}],
sizes:[{
type: String
}],
colors:[{
type: Schema.ObjectId,
ref: 'Color'
}],
frontColors:[{
type: Schema.ObjectId,
ref: 'Color'
}],
script: Boolean
},{
timestamps: true
});
var Err = mongoose.model('Err', errSchema);
module.exports = Err;
Code for workflow:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var colorSchema = new Schema({
name: String,
image: String,
rgb: String,
comment: String,
});
var Color = mongoose.model('Color', colorSchema);
module.exports = Color;
Any help would be appreciated!
source
share