diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-25 03:15:16 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-25 03:15:16 +0000 |
| commit | 3ca0e78b313a1bded021cbb8b2dad241d7cad049 (patch) | |
| tree | 021514c624008dfb32a3cdb1a9cb25ad01a2e5ba /node_simple.js | |
| parent | 34f553940cd5e9fba5ca6062333f42ba741b700a (diff) | |
| parent | 4ce98375d61429f2e41cfefe884df4f0640dd0a2 (diff) | |
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/node_simple.js b/node_simple.js index d2586e8..f8eb07d 100644 --- a/node_simple.js +++ b/node_simple.js @@ -89,6 +89,7 @@ var mongodb = exports.mongodb = require('mongodb'); var mongoFactory = exports.mongoFactory = require('mongo-factory'); var ObjectId = require('mongodb').ObjectID; var assert = require('assert'); +var _ = require('underscore'); // Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo'; @@ -337,6 +338,8 @@ exports.retrieve_userComments_history = function (username, callback) { mongoFactory.getConnection(uri).then(function (db) { var solutions = db.collection('solutions'); + var exams = db.collection('exams'); + var mylist = []; solutions.aggregate([ { $match : { @@ -352,14 +355,24 @@ exports.retrieve_userComments_history = function (username, callback) { exam_id: "$exam_id", _id: 0 }} - ]).toArray(function (err, results) { - if (err) callback(false, "Error: some weird error occurred while query"); - else { - callback(true, results); - } - + ]).toArray(function (err, res) { + var finised = _.after(res.length, doCall); // execute "doCall" only after res.length # of attempts + res.forEach(function (comment) { + exams.find( { _id: ObjectId(comment.exam_id) } ).toArray(function (err, docs) { // get the exam info + comment.course_code = docs[0].course_code; + comment.year = docs[0].year; + comment.term = docs[0].term; + mylist.push(comment); // save it to array + finised(); + }); + }); }); + function doCall() { + callback(true, mylist); + } + + }).catch(function (err) { // console.err(err); callback(false, "Error: failed to connect to db"); |
