const postSchema = mongoose.Schema({
title: String,
visit: { type: Number, default: 0
},
imagesrc: String,
tags: [
{ type: mongoose.Schema.Types.ObjectId,
ref: 'tag'
}
],
category: { type: mongoose.Schema.Types.ObjectId,
ref: 'category'
},
createTime: { type: Date, default: Date.now
},
lastEditTime: { type: Date, default: Date.now
},
hidden: Boolean,
excerpt: String,
content: String,
comments: [
{ type: mongoose.Schema.Types.ObjectId,
ref: 'comment'
}
]
}const categorySchema = mongoose.Schema({
name: String}文章和分類兩個模型定義如上,文章schema有一個分類的外鍵,請問如何最高效率的查詢出所有分類以及分類下的文章總數,返回一個集合
mongoose查詢所有分類下的文章總數
慕桂英4014372
2018-10-15 09:37:04
