Node.js 丢失模式错误:模式没有';“未注册型号”;App";
带有Node.js-Express-MongoDB的项目 当我运行应用程序时,出现以下错误Node.js 丢失模式错误:模式没有';“未注册型号”;App";,node.js,mongoose,Node.js,Mongoose,带有Node.js-Express-MongoDB的项目 当我运行应用程序时,出现以下错误 E:\asista\asistabot2\node_modules\mongoose\lib\index.js:337 throw new mongoose.Error.MissingSchemaError(name); ^ MissingSchemaError: Schema hasn't been registered for model "App". Use mongoose
E:\asista\asistabot2\node_modules\mongoose\lib\index.js:337
throw new mongoose.Error.MissingSchemaError(name);
^
MissingSchemaError: Schema hasn't been registered for model "App".
Use mongoose.model(name, schema)
at new MissingSchemaError (E:\asista\asistabot2\node_modules\mongoose\lib\error\missingSchema.js:20:11)
at Mongoose.model (E:\asista\asistabot2\node_modules\mongoose\lib\inde at Object.<anonymous> (E:\asista\asistabot2\app\controllers\chat.js:8: at Module._compile (module.js:643:30)
这是我聊天的一部分
const mongoose = require('mongoose');
const App =mongoose.model('App')
exports.chat =(req,res)=>{
res.send('i am inside chat ->');
};
像App.js这样提到的数据库模型
var mongoose = require('mongoose')
var Schema = mongoose.Schema;
var appSchema = new Schema({
agent_key:String
},{ collection: 'app' });
mongoose.model("app",appSchema);
我该怎么办?我怎么修理它 您没有定义架构 首先,您需要创建一个这样的模式
var appSchema = new Schema({
name: String
});
然后,从中创建一个模型
const App = mongoose.model('App', appSchema);
或者,您可以向模型函数提供模式
const App = mongoose.model('App', { name: String });
它的意思正是它所说的。而且您还没有提供
模式
@NeilLunn更新模型。您现在可以检查一下吗?您是否阅读了有关执行顺序的副本?听起来不像是你干的。
const App = mongoose.model('App', { name: String });