Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment Week4 <Ozlem Karaboga> #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Week4/homework/ex1-aggregation/mongodbOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getCountryPopulationByYear = async (country) => {
}
},
{
$sort: { _id: 1 }
$sort: { _id: 1 }
}
]).toArray();

Expand All @@ -31,7 +31,8 @@ const getCountryPopulationByYear = async (country) => {
};

// Function to retrieve continent information for a given Year and Age field
const getContinentInformationByYearAndAge = async (year, age) => {

const getAllContinentInformationByYearAndAge = async (year, age) => {
const client = new MongoClient(process.env.MONGODB_URL);
await client.connect();

Expand All @@ -44,11 +45,9 @@ const getContinentInformationByYearAndAge = async (year, age) => {
},
{
$addFields: {
TotalPopulation: { $add: ["$M", "$F"] }
TotalPopulation: { $add: ["$M", "$F"] },
Country: "$Country",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the fields to your result but it does not filter or aggregate per continent.

What we are looking for is something that in the end would have one object per continent year and age, lucky for us, the dataset already have those information, At this point you will need to look into the dataset itself to find if you have some data about continents instead of countries (maybe search for Europe and see what it result on)

I would advise, since the data is stored in mongodb to use the power from mongodb and javascript to figure our what the Country field can be and maybe search into it what could be used to have the data per continents

}
},
{
$sort: { _id: 1 }
}
]).toArray();

Expand All @@ -62,7 +61,7 @@ getCountryPopulationByYear("Netherlands").then((result) => {
console.log(result);
});

getContinentInformationByYearAndAge(2020, "100+").then((result) => {
getAllContinentInformationByYearAndAge(2020, "100+").then((result) => {
console.log("Continent information for 2020 and Age 100+:");
console.log(result);
});