【发布时间】:2015-12-07 03:22:01
【问题描述】:
我定义了几个模式。这是一个运行良好的:
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();
我收到主题中的错误。在跟踪代码时,我可以看到模块在范围内,所以我不相信它是愚蠢的,比如重新定义变量或类似的东西。
有什么想法吗?
【问题讨论】: