【发布时间】:2016-01-30 09:21:38
【问题描述】:
我定义了几个模式。这是一个运行良好的方法:
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();
我收到主题中的错误。在跟踪代码时,我可以看到模块在范围内,所以我不相信它是愚蠢的,比如重新定义变量或类似的东西。
这里发布了几个此类性质的问题,但没有一个被接受的答案适用。
有什么想法吗?
【问题讨论】:
-
为什么在你的代码中有这些随机空格?我的朋友,你肯定需要一个 linter :)
-
这里是粘贴到代码窗口,然后缩进让代码显示为代码的结果。