我设置了我的架构:
var videoSchema = new Schema({
title: String,
url: String, //Link to the video
rating: { type: Number, default: 0},
description: String //a paragraph or two to go along with the video
});
var tutorialPageSchema = new Schema({
title: String, //IE Peeking, Clutching, etc.
tutorials: [videoSchema]
});
var categorySchema = new Schema({
title: String, //intermediate, beginner, config, map knowledge, etc.
pages: [tutorialPageSchema]
});
exports.Video = mongoose.model('video', videoSchema);
exports.TutorialPage = mongoose.model('tutorialPage', tutorialPageSchema);
exports.Category = mongoose.model('category', categorySchema);
像这样添加文档:
var newPage = new models.TutorialPage({
title: req.query.page.title,
tutorials: []
});
parentCategory.pages.push(newPage);
作为回报,它给了我一个很好的“TypeError:无法调用未定义的方法'push' “
其他时候问的问题是,人们没有按照正确的顺序加载模式,或者在设置模式时将模型与模式混为一谈,但这似乎不是我的问题。是什么给了什么?