想弄个简单的文章发布系统,所有文章需要属于一个分类,求教数据库怎么设计,一级就够。新手刚学数据库这块。。
//文章模型
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var AticleSchema = new Schema({
title: { type: String },
author_id: { type: String},
content:{type:String},
create_at: { type: Date, default: Date.now },
update_at: { type: Date, default: Date.now },
});
AticleSchema.index({title: 1}, {unique: true});
mongoose.model('Aticle', AticleSchema);
The simplest and crudest way is to create two schemas, one for articles and one for article classification, through table association.
1. Schema of classified documents
2. The schema of another article document is the same as the one you wrote yourself, with just a few modifications
Add the rest of the code your way.
How to create multiple categories and categories? How to do it