im having some trouble with my MongoDB aggregation. I have documents like:
{
_id: "123456",
values: [
{
"value": "A",
"begin":0,
"end":1,
}
{
"value": "B",
"begin":1,
"end":2,
}
{
"value": "C",
"begin":3,
"end":7,
}
],
"name": "test"
}
And i want to count only the "value" in "values". With some help i got the following aggregation:
db.collection.aggregate([
{$unwind: "$values"},
{$group: {_id: "$values.value", count: {$sum: 1}}}
])
The problem is: it takes me about 20 seconds to get the result for 6k documents. Is there anything i can do for optimication?
Greetings