Mongoose if (!this.modelSchemas[name]) 错误
Mongoose if (!this.modelSchemas[name]) error
每当我尝试使用下面的代码连接时,
const mongoose = require('mongoose');
// var Model = mongoose.model.bind(mongoose); didnt work
var imageSchema = new mongoose.Schema({
name: String,
dob: String,
breed: String,
details: String,
img:
{
data: Buffer,
contentType: String
}
});
module.exports = new mongoose.model('Image', imageSchema);
我在控制台中记录了这个错误
if (!this.modelSchemas[name]) {
^
TypeError: Cannot read property 'Image' of undefined
我已经按照另一页的建议尝试了模型绑定猫鼬,但效果不佳
model
是returns模型的一种方法。你不应该用 new
:
来调用它
module.exports = mongoose.model('Image', imageSchema);
每当我尝试使用下面的代码连接时,
const mongoose = require('mongoose');
// var Model = mongoose.model.bind(mongoose); didnt work
var imageSchema = new mongoose.Schema({
name: String,
dob: String,
breed: String,
details: String,
img:
{
data: Buffer,
contentType: String
}
});
module.exports = new mongoose.model('Image', imageSchema);
我在控制台中记录了这个错误
if (!this.modelSchemas[name]) {
^
TypeError: Cannot read property 'Image' of undefined
我已经按照另一页的建议尝试了模型绑定猫鼬,但效果不佳
model
是returns模型的一种方法。你不应该用 new
:
module.exports = mongoose.model('Image', imageSchema);