当前位置 : 主页 > 网页制作 > Nodejs >

node.js – Mongoose:“TypeError:Undefined type at”

来源:互联网 收集:自由互联 发布时间:2021-06-16
我有一个使用猫鼬的模块.我的主要项目也使用猫鼬.我发现我无法使用模块与项目架构的连接.看例子: var mod = require('module_with_mongoose_connection');var mongoose = require('mongoose');var SessionSchem
我有一个使用猫鼬的模块.我的主要项目也使用猫鼬.我发现我无法使用模块与项目架构的连接.看例子:

var mod = require('module_with_mongoose_connection');
var mongoose = require('mongoose');

var SessionSchema = new mongoose.Schema({ // replacing this with `mod.mongoose.Schema` works
...
});
mod.mongooseConnection.model('session', SessionSchema);

上面的例子抛出

throw new TypeError('Undefined type at `' + path +
          ^
TypeError: Undefined type at `paths.name`
  Did you try nesting Schemas? You can only nest using refs or arrays.
    at Function.Schema.interpretAsType (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:397:11)
    at Schema.path (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:334:29)
    at Schema.add (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:245:12)
    at Schema.add (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:240:14)
    at new Schema (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:72:10)
Why is that? A bug?

这个问题的解决方案是什么?一个bug?

我有同样的错误,我的问题是我的require语句中有拼写错误:

var mongoose = require('Mongoose'); // Don't do this

var mongoose = require('mongoose'); // Use a lowercase 'm'
网友评论