I have model schema in ./model.js file
const ImageSchema = new mongoose.Schema(
{
name: { type: String },
filePath: { type: String },
},
{ timestamps: true }
);
module.exports = mongoose.model("ImageSchema", ImageSchema);
seed.js
seeder.connect(
"mongoURI",{useUnifiedTopology: true},
function () {
seeder.loadModels('./model.js');
seeder.clearModels(['ImageSchema'], function () {
seeder.populateModels(data, function () {
seeder.disconnect();
});
});
}
);
var data = [
{
'model': 'ImageSchema',
'documents': [
{
'name': "Image",
'filePath': "/api/image"
}
]
}
]
When I run seed.js file then it says.
UnhandledPromiseRejectionWarning: TypeError: modelPaths.forEach is not a function at Seeder.loadModels
Later, I got to know from the comment below that seeder.loadModels() takes an array of paths and I fixed it. Now another issue. It says, Error: Models not registered in Mongoose: ImageSchema.
MyFolder structure is
seeder/
model.js
seed.js