是否可以使用MongoDB在聚合函数中对映射中的值进行分组?
我的数据集如下:是否可以使用MongoDB在聚合函数中对映射中的值进行分组?,mongodb,aggregation-framework,Mongodb,Aggregation Framework,我的数据集如下: { _id: "joe", email: "joe@joe.com", attributes: [ "eyes" : "blue", "height" : "6'0" ] } 是否可以通过将属性映射中的特定值分组来执行聚合 即 您可以按如下方式进行操作: db.myObject.aggregate( {$unwind : "$attributes"}, {$group : {_id : {eyes : "$attributes.eyes"},
{
_id: "joe",
email: "joe@joe.com",
attributes: [ "eyes" : "blue", "height" : "6'0" ]
}
是否可以通过将属性映射中的特定值分组来执行聚合
即
您可以按如下方式进行操作:
db.myObject.aggregate(
{$unwind : "$attributes"},
{$group : {_id : {eyes : "$attributes.eyes"}, number : {$sum:1}}}
);
db.myObject.aggregate(
{$unwind : "$attributes"},
{$group : {_id : {eyes : "$attributes.eyes"}, number : {$sum:1}}}
);