【发布时间】:2015-06-26 02:26:17
【问题描述】:
我不明白为什么我可以使用这个来访问我的模型:
module.exports = function(mongoose) {
var collection = 'news';
var NewsSchema = new mongoose.Schema({
type: String,
content: String,
img: String,
date: {type: Date, default: Date.now }
});
return mongoose.model(collection, NewsSchema);
}
但我必须指定名称集合才能访问此模型:
module.exports = function(mongoose) {
var collection = 'console';
var ConsoleSchema = new mongoose.Schema({
value: String,
label: String
}, { collection: collection });
return mongoose.model(collection, ConsoleSchema);
}
我使用
访问我的数据models.news.find({});
models.collection.find({});
我不明白这些技巧......
谢谢
【问题讨论】:
标签: node.js model mongoose schema