I am a beginner in MongoDB and I am learning aggregations. I have the following document which is information from Inflation, it looks like this:
{
"_id": {
"$oid": "60678f561091100d5dbe2ddf"
},
"V": 0.21,
"D1C": "202001",
"D2C": 63,
"D3C": 7169,
},
{
"_id": {
"$oid": "60678f561091100d5dbe2de0"
},
"V": 0.39,
"D1C": "202001",
"D2C": 63,
"D3C": 7170,
},
{
"_id": {
"$oid": "60678f561091100d5dbe2de1"
},
"V": 0.2,
"D1C": "202001",
"D2C": 63,
"D3C": 7171,
},
(...)
{
"_id": {
"$oid": "60678f561091100d5dbe2fa8"
},
"V": 0.21,
"D1C": "202001",
"D2C": 69,
"D3C": 7169,
},
{
"_id": {
"$oid": "60678f561091100d5dbe2fa9"
}
"V": 0.39,
"D1C": "202001",
"D2C": 69,
"D3C": 7170,
}
"V" is the value of the inflation, "D1C" is the month, "D2C" is the type of index (i.e. % yearly accumulated or % monthly) and "D3C" is the group of inflation (i.e. Food, Industry, Services).
I wanted to aggregate this data in such a way that would be easy to chose an arbitrary value of "D2C" and import the data into a pandas dataframe.
More specifically i wish i had the data in a way I could ask only for D2C=63 and get something like this:
[ { "7169" : {'01/2020' : 0.21, '02/2020' : 0.66, ...},
{ "5555" : {'01/2020' : 0.21, '02/2020' : 0.66, ...},]
In a way that i get all the groups as keys of a dict and the value would be a dict with pairs of the date and values referring to the group.
Thank you everyone, and happy easter!