Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.get('/player/:year', function(req, res) {
- var db = req.db;
- var collection = db.get('ratings');
- var year = req.param('year');
- collection.find({'sbYear': year}, ['Player_ID'], function(e, docs) {
- var players = [];
- var info = db.get('player_information');
- var wait = docs.length;
- docs.forEach(function(player) {
- var playerId = player.Player_ID;
- info.findOne({'Player_ID': playerId}, ['Player_ID', 'First_Name', 'Last_Name', 'Position' ], function(e, docs) {
- players.push(docs);
- wait--;
- });
- });
- function waitForCompletion() {
- if (wait > 0) {
- console.log("Wait is " + wait);
- setTimeout(waitForCompletion, 100);
- return;
- }
- res.send(JSON.stringify(players));
- }
- waitForCompletion();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement