In a standard SQL DBMS, this will be done with the following query:
SELECT type, count(*) as ct FROM table GROUP BY type ORDER BY ct;
on mongodb this would be done using a group function, although it is somewhat more complicated:
db.collection.group(
{key: { "type":true},
reduce: function(obj,prev) { prev.count += 1; },
initial: { count: 0 }
});
db "type" (, "true" ), . , . , - :
[
{
"type" : "report",
"count" : 5
},
{
"type" : "memo",
"count" : 15
}
{
"type" : "research",
"count" : 3
}
]
, ; mongodb docs , - .
.