I'm very new to the MongoDb. With that said, my csv file data is as below which are about yearly expenses.
{"Name": "Aruba",
"Code": "ABW",
"Type": "Country",
"IndicatorName": "Military_expenditure",
"1900": 0,
"1961": 1,
"1962": 0,
"1963": 0,
"1964": 0,
"1965": 0,
"1966": 0,
"1967": 0,
"1968": 0,
"1969": 0
}, {
"Name": "Afghanistan",
"Code": "AFG",
"Type": "Country",
"IndicatorName": "Military_expenditure",
"1900": 0,
"1961": 100,
"1962": 0,
"1963": 0,
"1964": 0,
"1965": 0,
"1966": 0,
"1967": 0,
"1968": 0,
"1969": 0
}
However, I need to get the summation of
- Total yearly expenses, that is
Aruba=1 >> (1900=0 + 1961=1......+ 1969=0} Afghanistan = 100 >> (1900=0 + 1961=100......+ 1969=0}
- Total Expense of the countries =101
Aruba (1900=0 + 1961=1......+ 1969=0} + Afghanistan(1900=0 + 1961=100......+ 1969=0}
can someone please help to do the above calculations in MongoDb
However, I have written query to get the year wise summation
db.MiltryExpenditure.aggregate([
{ $match: { "Type":"Country" } },
{$group:{_id : null,
1969: { $sum: { "$toDouble":"$1969" }}
, _id : null,
1960: { $sum: {
"$toDouble":"$1960" }},
}}
])
But I don't know how to get the Total summation of the countries, as well as if theirs a normalize method to get the country wise summation , that would be much appreciated.
Please Help...
"Name": "Afghanistan"or"Name": "Aruba"like that ?