I have a "product" collection which has a "category" field. I am trying to get count of distinct categories. I can't use db.product.distinct("category").length as it exceeds 16mb cap with below error:-
> db.product.distinct("category").length
2014-07-21T08:58:25.289-0400 distinct failed: {
"errmsg" : "exception: distinct too big, 16mb cap",
"code" : 17217,
"ok" : 0
} at src/mongo/shell/collection.js:1108
So,I am using aggregation framework for this and I am able to get count using this query:-
db.product.aggregate([{$group: {_id:"$category"}}, {$group: {_id:"", count:{$sum:1}}}], {allowDiskUse: true})
I am not able to translate this into spring data mongodb aggregation query. Please help. I am getting following errors with what I have tried:
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group("category"),
Aggregation.group(" ").count().as("numDistinctCategories"));
Error: AggregationField can't be null. I have tried other strings in second group operation but it gives Invalid reference error.