I'm trying to find a count embedded document keys across documents in a collection. For example:
doc1 = {
field1: 'foo',
field2: {
12322 = {
...
},
244 = {
...
},
8791 = {
...
}
}
}
doc2 = {
field1: 'bar',
field2: {
789 = {
...
},
244 = {
...
},
8791 = {
...
},
12 = {
...
}
}
}
I'd like to run an aggregation where I can get the count of these keys.
Result
{
12: 1,
244: 2.
789: 1,
8791: 2,
12322: 1
}
Bonus: one of the fields in each of those embedded docs is a date field, I'm eventually going to need to filter out objects that are older than a certain date.