【发布时间】:2014-10-15 21:33:50
【问题描述】:
我有以下架构,我试图将一组 cmets 添加到我的博客文章架构中,然后在 cmets 架构内我需要添加一组与每个特定评论相关的图片 url。我研究了网络,发现这个链接 embedded documents 到 mongoose 文档,但注意到它与 mongoose 2.7 版有关,而我们目前是 3.8 版。所以想知道我做对了吗?如果不是,有人可以通过建议设计我的博客文章架构的最佳方法来帮助我,以便它包含 cmets 的博客文章数组以及与每个相关的图片数组评论。感谢您的时间和精力。
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var pictures = new Schema({
picURL: String,
date: {
type: Date,
default: Date.now
}
});
var comments = new Schema({
subject: String,
body: String,
date: {
type: Date,
default: Date.now
},
pictures:[pictures]
});
var blogpost = new Schema({
title: String,
body: String,
date: {
type: Date,
default: Date.now
},
comments:[comments]
});
module.exports = mongoose.model('BlogPost', blogpost);
【问题讨论】: