【发布时间】:2019-06-18 13:17:36
【问题描述】:
我正在使用 Nodejs 和 MongoDB 以及 expressjs 和 mongoose 库,创建一个具有 用户 的 Blog API, 文章 & cmets 架构。以下是我使用的架构。
const UsersSchema = new mongoose.Schema({
username: { type: String },
email: { type: String },
date_created: { type: Date },
last_modified: { type: Date }
});
const ArticleSchema = new mongoose.Schema({
id: { type: String, required: true },
text: { type: String, required: true },
posted_by: { type: Schema.Types.ObjectId, ref: 'User', required: true },
images: [{ type: String }],
date_created: { type: Date },
last_modified: { type: Date }
});
const CommentSchema = new mongoose.Schema({
id: { type: String, required: true },
commented_by: { type: Schema.Types.ObjectId, ref: 'User', required: true },
article: { type: Schema.Types.ObjectId, ref: 'Article' },
text: { type: String, required: true },
date_created: { type: Date },
last_modified: { type: Date }
});
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework