您可以在此链接中查看完整代码here
> function seedDB () {
Campgrounds.remove({},function(err){
if (err) {
console.log(err);
}
else {
console.log("Removed All Camping Sites!");
data.forEach(function(seed){
Campgrounds.create(seed,function(err){
if (err) {
console.log(err);
}
else {
console.log("A Campground Has Been Successfully Added!");
Comments.create ({
title:"Really Great Place, Definately worth it.",
author:"Chris"
},function(err,comment){
if (err) {
console.log(err);
}
else {
Campgrounds.comments.push(comment);
Campgrounds.save();
console.log("comment added");
}
});
}
});
});
}
});
}
一切正常,直到Campgrounds.comments.push(...)都抛出错误“无法读取未定义的类似内容。所有模块和文件都包含在我的github中。”