Monday, November 21, 2016

[Solution] Week 6 : The Aggregation Framework : M101JS: MongoDB for Node.js Developers

 [Solution] Week 6 : The Aggregation Framework : M101JS: MongoDB for Node.js Developers


Homework 6.1 : 


Starting with the example we looked at for calculating the total number of relationships individuals have participated in (in the CrunchBase data set):

db.companies.aggregate( [
    { $match: { "relationships.person": { $ne: null } } },
    { $project: { relationships: 1, _id: 0 } },
    { $unwind: "$relationships" },
    { $group: {
        _id: "$relationships.person",
        count: { $sum: 1 }
    } },
    { $sort: { count: -1 } }
] )

Write an aggregation query that will determine the number of unique companies with which an individual has been associated. To test that you wrote your aggregation query correctly, from the choices below, select the number of unique companies that Eric Di Benedetto (eric-di-benedetto) has been associated with. I've attached the CrunchBase data set for use in this problem.

Hint: Review the available accumulators before beginning this exercise.

As a check on your work, the number of unique companies for roger-ehrenberg is 16, for josh-stein is 14, and the number for tim-hanlon actually is 28.

Solution : 15

Solution Mongodb m101js Homework 6.1,visionfortech,mongodb solutions for m101js,Pratik Soni







Homework 6.2 : 


Who is the easiest grader on campus?

Download the handout and import the grades collection using the following command.

mongoimport --drop -d test -c grades grades.json
Documents in the grades collection look like this.

{
    "_id" : ObjectId("50b59cd75bed76f46522c392"),
    "student_id" : 10,
    "class_id" : 5,
    "scores" : [
        {
            "type" : "exam",
            "score" : 69.17634380939022
        },
        {
            "type" : "quiz",
            "score" : 61.20182926719762
        },
        {
            "type" : "homework",
            "score" : 73.3293624199466
        },
        {
            "type" : "homework",
            "score" : 15.206314042622903
        },
        {
            "type" : "homework",
            "score" : 36.75297723087603
        },
        {
            "type" : "homework",
            "score" : 64.42913107330241
        }
    ]
}

There are documents for each student (student_id) across a variety of classes (class_id). Note that not all students in the same class have the same exact number of assessments. Some students have three homework assignments, etc.

Your task is to calculate the class with the best average student performance. This involves calculating an average for each student in each class of all non-quiz assessments and then averaging those numbers to get a class average. To be clear, each student's average should include only exams and homework grades. Don't include their quiz scores in the calculation.

What is the class_id which has the highest average student performance? Choose the correct class_id below.


Solution : 1


Solution Mongodb m101js Homework 6.2,visionfortech,mongodb solution m101js week 6








Homework 6.3 :


For companies in our collection founded in 2004 and having 5 or more rounds of funding, calculate the average amount raised in each round of funding. Which company meeting these criteria raised the smallest average amount of money per funding round? You do not need to distinguish between currencies. Write an aggregation query to answer this question.

As a check on your solution, Facebook had the largest funding round average.

Solution : Nimbit

Solution Mongodb m101js Homework 6.3 ,visionfortech,pratik Soni Blog
















Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Related Post : 

1) [SOLUTION] WEEK 1 : INTRODUCTION : M101JS: MongoDB for Node.js Developers

2) [SOLUTION] WEEK 2 : CRUD : M101JS: MongoDB for Node.js Developers

3) [SOLUTION] Week 3 :The Node.js Driver : M101JS: MongoDB for Node.js Developers

4) [SOLUTION] WEEK 4 : SCHEMA DESIGN : M101JS: MongoDB for Node.js Developers

5) [SOLUTION] WEEK 5 : INDEXES AND PERFORMANCE : M101JS: MongoDB for Node.js Developers

6) [SOLUTION] WEEK 6 : THE AGGREGATION FRAMEWORK : MongoDB for Node.js Developers

7) [SOLUTION] WEEK 7 :APPLICATION ENGINEERING : MongoDB for Node.js Developers

8) [SOLUTION] FINAL EXAM(PROJECT) :MONGOMART APPLICATION : M101JS: MongoDB for Node.js Developers

4 comments:

  1. Can you send me the aggregation Query for HW6.1

    ReplyDelete
  2. For HW6.3 The Aggregation Querry:
    db.getCollection('companies').aggregate([{$match:{"founded_year":2004}},{$project:{_id:0,name:1,"funding_rounds.raised_amount":1,size:{$size:"$funding_rounds"}}},{$match:{size:{$gte:5}}},{$project:{name:1,avg:{$avg:"$funding_rounds.raised_amount"}}},{$sort:{avg:1}}])

    ReplyDelete
  3. For HW6.2:
    db.grades.aggregate( [
    { $project: { _id: 0, class_id: 1, student_id: 1, "scores": 1 } },
    { $unwind: "$scores" },
    { $match: { "scores.type": { $ne: "quiz" } } },
    { $group: {
    _id: {
    class_id: "$class_id",
    student_id: "$student_id"
    },
    avg: { $avg: "$scores.score" }
    } },
    { $project: { '_id.class_id': 1, avg: 1 } },
    { $group: {
    _id: "$_id.class_id",
    avg: { $avg: "$avg" }
    } },
    { $sort: { avg: -1 } }
    ] )

    ReplyDelete
  4. You have really selected the suitable topic node.js development ; this is one of my favorite blogs.
    node.js development services

    ReplyDelete

Protected by Copyscape