是否可以制作一组外部猫鼬模式? 当我这样运行时,控制台会说:
TypeError: Invalid value for schema Array path `comments`, got value "undefined"
comment.js
const mongoose = require('mongoose');
const commentScheme = new mongoose.Schema({
body: String,
author: {
id: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
username: String
}
});
module.exports = mongoose.model('Comment', commentScheme);
campground.js
const mongoose = require('mongoose'),
Comment = require('./comment');
const campgroundSchema = new mongoose.Schema({
name: String,
image: String,
desc: String,
comments: [ Comment.commentSchema ]
});
module.exports = mongoose.model('Campground', campgroundSchema);
答案 0 :(得分:0)
是的,
您只需要更换
comments: [ Comment.commentSchema ]
使用
comments: [ Comment.schema ]
祝你好运!