Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
2.1.2
-
Query
Description
here's a list of documents:
{_id:1, manufacturer: "Sony", features: ["fast", "sleek", "sexy"]} |
{_id:2, manufacturer: "Sony", features: ["lightweight", "sleek"]} |
{_id:3, manufacturer: "Sony", features: ["cheap", "fast"]} |
{_id:4, manufacturer: "Apple", features: ["fast", "sleek", "usable"]} |
{_id:5, manufacturer: "Apple", features: ["lightweight", "sleek", "cheap"]} |
{_id:6, manufacturer: "Apple", features: ["fast", "usable", "codecs"]} |
I'd like to output to look like:
{
|
"manufacturer": { |
"Sony":3, |
"Apple":3 |
},
|
"features": { |
"fast": 4, |
"cheap": 2, |
"codecs": 1, |
"usable": 2, |
"lightweight": 2, |
"sleek": 3, |
"sexy": 1, |
}
|
}
|
Here's my opinion on how to make this request:
db.coll.aggregate(
|
{$count: ["manufacturer", "features"]} |
)
|
Alternately, I'd be fine with a new group aggregation function, like so:
db.coll.aggregate({
|
$group: {
|
manufacturer: {$count: "$manufacturer"}, |
features: {$count: "$features"} |
}
|
})
|
Although this obviously requires that the need to specify an _id be lifted, or accounted for in some way.
Attachments
Issue Links
- is related to
-
SERVER-12927 Support ROLLUP function in the $group aggregation operator
-
- Backlog
-
-
SERVER-23836 add $count stage to aggregation
-
- Closed
-