Node.js 未定义ReferenceError项目

Node.js 未定义ReferenceError项目,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我定义了几个模式。这里有一个很好用的: var mongoose = require('mongoose'), Schema = mongoose.Schema; var NewsSchema = new Schema({ name: String, route: String, remoteURL: String, articles: [{title: String, link: String, Image: String, cont

我定义了几个模式。这里有一个很好用的:

var mongoose     = require('mongoose'), 
Schema       = mongoose.Schema;

var NewsSchema   = new Schema({
    name: String,
    route: String,
    remoteURL: String,
    articles: [{title: String, link: String, Image: String, contentSnippet: String}],
    retrieved: Date,
    dormant: { type: Boolean, default: false}
});
module.exports = mongoose.model('News', NewsSchema);
这是第二个几乎相同的:

var mongoose     = require('mongoose'), 
Schema       = mongoose.Schema
// NewsSchema = new Schema({ name: String });   

var ArticlesSchema   = new Schema({
    title: String,
    link: String,
    pubDate: Date,
    image: String,
    contentSnippet: String,
    sourceName: String
    // sourceId: [ {type: Schema.Types.ObjectId, ref: NewsSchema}]
});

module.exports = mongoose.model('Articles', ArticlesSchema);
我已经在程序顶部加载了这两个模块,以及其他类似的东西:

players = require('./app/models/players'),
articles = require('./app/models/articles'),
如果我创建第一个实例的实例,如下所示:

var player = new Players();
但是,如果我尝试创建第二个实例,其中包含:

var item = new Articles();
我收到了主题中的错误。在跟踪代码时,我可以看到模块在范围内,所以我不认为这是像重新定义变量之类的愚蠢行为

这里有几个这样性质的问题,没有一个被接受的答案适用


有什么想法吗

好吧,进一步分析后,有效的“模型”不再有效。事实证明,我已经根据VisualStudio代码的建议,在顶部的require语句中修改了案例。现在一切都好了

而不是 sourceId:[{type:Schema.Types.ObjectId,ref:newschema}] 使用 sourceId:[{type:Schema.Types.ObjectId,ref:'newschema'}]
可以解决您的问题

为什么代码中有这么多随机空格?你肯定需要一个过梁,我的朋友:)这是粘贴到代码窗口的结果,然后缩进以使代码显示为代码。