Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MongoDB questions 1. Count the number of records that is between year of 1870 to

ID: 3571525 • Letter: M

Question

MongoDB questions

1. Count the number of records that is between year of 1870 to 1880

2. Which player_id has the highest ipouts?

3. Find average year in the whole pitching collection

4. Group the players by year and return the average ipouts per year

5. Find out the players with max era and min era per year

6. Find out the average, maximun and minimum h and er per team_id

7. Find out the average, maximun and minimum h and er per team_id and year

8. Order the team_id by the number of players in the team and group by year

Here's an example of pitching database

player id year, stint team d,league id, w,l,g, gs,cg, sho, sh, r hr bb, so, baopp, era, ibb, wp, hbp, bk,bfp, sh, sf, idp ipouts, bechtge01, 1871,1, PH1 1,2,3,3,2,0, 0,78.0,43, 23,0, 11,1, 7.96 42 brain 1,WS3, 12,15,30,30,30,0 0,792. 361,132, 4,37,13 4.5 292

Explanation / Answer

1. Count the number of records that is between year of 1870 to 1880:

By using the cursor.count() we can count number of records availble in between the years.

SYNTAX: The syntax for count() are as follows.
db.collection.find(< query statement >).count()

Eg: db.collection.find( { Date('01/01/1870 $bt '31/12/1880') } ).count()

2.Which player_id has the highest ipouts?

This can be done by using the find().it will retuns the player_id with high ipouts.
Eg: db.collection.find().sort({_id: -1}).limit(1)

3.Find average year in the whole pitching collection.
BY using the aggregation $avg returns average value of the numeric values by ignoring non-numeric values.
syntax:{$avg: <Statement>}
we can also define multiple statements as follows.
{$avg: [<statment1,statement2,.....statementn>]}
eg: db.pitching.aggregate([{$Year:{ $avg:"Year" }}])

4.Group the players by year and return the average ipouts per year
this can be done by using the grouping statementas follows
Eg:db.pitching.aggregate([{$group:{_year:null,pop:{$avg:"$ipouts"}}}])

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote