如题 现在有三个 Schema Article
var ArticleSchema = new Schema({
title: {type: String},
content: {type: String},
source: {type: String},
top: {type: Boolean, default: false},
created_at: {type: Date, default: Date.now},
updated_at: {type: Date, default: Date.now},
views: {type: Number, default: 0},
comments: {type: Number, default: 0},
cat: {type: Number}
}, {
toJSON: {virtuals: true}
});
Tag
var TagSchema = new Schema({
_id: {
type: String,
unique: true,
default: shortId.generate
},
name: {type: String}
});
TagMap
var TagMapSchema = new Schema({
_id: {
type: String,
unique: true,
default: shortId.generate
},
article_id: {type: String},
tag_id: {type: String}
});
想要实现通过Tag查询到文章,并且文章也能查询到包含的Tag