CALL_NON_FUNCTION_AS_CONSTRUCTOR(本机)

我试图在我的数据库中使用新的模式,但尝试实例化时得到错误。 我有两个其他模式(在“模型”文件夹中的两个不同的模型文件),这是完美的,他们的形状相同的方式。 错误信息是什么意思,我可以做什么不同,以防止它发生?

我不认为它在控制器中的其他代码的任何问题,因为我试图在相同的地方使用相同的语法实例化另一个数据库模型,并且工作正常。

我得到的错误: 500 TypeError:对象不是在Schema.CALL_NON_FUNCTION_AS_CONSTRUCTOR(本机)函数

对不起,下面的所有代码。 在这种情况下,我不知道我能排除什么。 无论如何,先谢谢了!

控制器文件:

module.exports = function(app, service) { var imageModel = service.useModel('image'); app.post('/file-upload', function(req, res, next) { // other code... var imageAdd = new imageModel.ImgSchema(); } } 

mongodb模型(models / image.js):

 module.exports = function (mongoose) { var modelObject = {}; var Schema = mongoose.Schema, ObjectId = Schema.ObjectId; var ImgSchema = new Schema({ name : String, size : Number, type : String }); modelObject.ImgSchema = ImgSchema; modelObject.Images = mongoose.model('Images', ImgSchema); return modelObject; }; 

对于MongoDB,我使用了一个服务文件(service.js):

 var environment; var mongoose = require('mongoose'); module.exports.init = function(env, mongoose) { environment = env; mongoose = mongoose; }; module.exports.useModel = function (modelName) { var checkConnectionExists = (mongoose.connection.readyState === 1 || mongoose.connection.readyState === 2); if(!checkConnectionExists) mongoose.connect(environment.db.URL); return require("./models/" + modelName)(mongoose); }; module.exports.useModule = function (moduleName) { return require("./modules/" + moduleName); }; 

modelObject.ImgSchema不是一个构造函数,但是,modelObject.Images是。

 var imageAdd = new imageModel.Images(); 

我可能会将图像重命名为图像