我有以下查询:
uno = db.prueba.aggregate(
{$project: {a_gt_b: {$cmp: ['$num-a','$num-b']}}},
{$match: {a_gt_b:{$gt:0}}},
{$group:{"_id":"$a_gt_b",total:{"$sum":1}}},
{$project: {"_id":0,"total":1}}
);
我想执行$explain命令,根据这个答案,我必须接受$match部分,但我不知道如何。
这个答案超级过时了(我会更新它)。从 Mongo 2.6 开始,您可以解释聚合结果:
db.orders.aggregate([
# put your whole aggregation query
], {
explain: true
})