【发布时间】:2015-08-18 16:11:08
【问题描述】:
我正在 Node.js 中创建一个以 mongodb 作为数据库的博客系统。
我有这样的内容:(博客文章):
// COMMENTS SCHEMA:
// ---------------------------------------
var Comments = new Schema({
author: {
type: String
},
content: {
type: String
},
date_entered: {
type: Date,
default: Date.now
}
});
exports.Comments = mongoose.model('Comments',Comments);
var Tags = new Schema({
name: {
type: String
}
});
exports.Tags = mongoose.model('Tags',Tags);
// CONTENT SCHEMA:
// ---------------------------------------
exports.Contents = mongoose.model('Contents', new Schema({
title: {
type: String
},
author: {
type: String
},
permalink: {
type: String,
unique: true,
sparse: true
},
catagory: {
type: String,
default: ''
},
content: {
type: String
},
date_entered: {
type: Date,
default: Date.now
},
status: {
type: Number
},
comments: [Comments],
tags: [Tags]
}));
我对这种类型的数据库有点陌生,我习惯于使用 LAMP 堆栈上的 MySQL。
基本上我的问题如下:
- 将内容作者与用户关联的最佳方式是什么? 数据库?
- 另外,标记和分类的最佳方式是什么?
在 MYSQL 中,我们将有一个标签表和一个类别表,并通过键关联,我不确定在 Mongo 中最好和最优化的方式。
感谢您的宝贵时间!!
【问题讨论】: