node.js - 猫鼬 if (!this.modelSchemas[name]) 错误
问题描述
每当我尝试使用下面的代码进行连接时,
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
是返回模型的方法。你不应该用它来调用它new
:
module.exports = mongoose.model('Image', imageSchema);
推荐阅读
- sql - SQL Server 2019 - 添加日期和时间组件
- javascript - 我正在尝试用 JavaScript 编写 Discord 机器人,但遇到了问题
- bash - 在以下情况下,/bin/bash $0 $0 在第 5 行做什么?
- python - 有概率的简单突变
- c# - Entity Framework C# Table 未使用 add 方法更新数据
- sql-server - 如何按月划分金额和订单?sql服务器
- c++ - 输入数据的时间复杂度
- python - TensorFlow 2.x:无法以 h5 格式保存训练模型(OSError:无法创建链接(名称已存在))
- c# - HttpClient Polly 超时策略
- python - {Discord.py-rewrite} Bot 命令在我有“On Message”事件时不起作用