In: Computer Science
covert to MongoDB NoSQL
a. In 1990, in what games and what Seattle players had interceptions in a game?
Select games.game_number, profiles.name from games, profiles where games.defense_interceptions <>0 and games.team=”SEA” and games.year=”1990” and games.player_id = profiles.player_id;
b. For each year played, list a count of games in which John David Crow played.
select year, count(*) from profiles natural join games where name=”John David Crow” group by year;
a.
db.games,profiles .find({
"$and": [{
"games.defense_interceptions
<":{ "$gt" : 0 }
},{
"$and": [{
"$where": "this. games.team ==
this.”SEA” "
},{
"$and": [{
" games.year" : ”1990”
},{ "$where": "this. games.player_id ==
this. profiles.player_id"
}]
}]
}]
},{
"games.game_number": 1,
"profiles.name": 1
}
);
b.
db.profilesnatural join games .group({
"key":{
"year": true
},
"initial": {
"countstar":0
},
"reduce": function( obj , prev ){
if (true != null ) if ( true instanceof Array)prev.countstar +=
true.length;
else prev.countstar++;
},
"finalize": function( prev ){
},
"cond": {
"$where": "this.name == this.”John David Crow” "
}
});