【发布时间】:2014-05-09 10:42:40
【问题描述】:
正如我上面写的,我有一个引用另一个不同模式的模式。它们是:
exports.Policies = new mongoose.Schema({
name: String,
description: String,
exploits: [ {type : mongoose.Schema.ObjectId, ref : 'exploit', required: true} ]
});
exports.exploit = new mongoose.Schema({
name: String,
type: String,
required: [String]
});
我想要做的只是知道有多少值有 'exploits' 数组作为响应中的一个字段,这可能吗?在sql中我只需要写“count(field)”并进行“group by”,我该怎么做?
一个例子:
{
"name" : "mmmmmm",
"description" : "jjjj",
"_id" : ObjectId("533721b91a985b883399cdc2"),
"n_exploits" : 2
}
提前致谢。
【问题讨论】:
标签: node.js mongodb mongoose aggregation-framework