From 98c9cbc6258f699fc944f025230c35faf8575bc2 Mon Sep 17 00:00:00 2001 From: kdam0 Date: Mon, 30 Jan 2017 00:02:09 -0500 Subject: feat. added auto fill for search bar. --- node_simple.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 2f49360..e991515 100644 --- a/node_simple.js +++ b/node_simple.js @@ -117,6 +117,7 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/ exports.setupDB = function (callback) { mongoFactory.getConnection(uri).then(function (database) { db = database; + // var corses = exports.find_all_course_codes_from_exams(); callback(true, "Database connected"); // signal start of app }).catch(function (err) { @@ -648,6 +649,28 @@ exports.updatePassword = function (email, password, callback) { /************************* COURSES / EXAMS **********************************/ + +/** + * Find all UNIQUE course codes from EXAMS collection + * + * @param {function} callback: 2 args: (), + * where : couseCodes array + */ +exports.find_all_course_codes_from_exams = function (callback) { + var exams = db.collection('exams'); + exams.distinct("course_code", function (err, result) { + if (err) throw console.log(err); + else { + // console.log(result); + callback(result); + } + }); + + // callback(unique_coursecodes.distinct('course_code')); + // return (unique_coursecodes.distinct('course_code')); +}; + + /** * Remvove a course from ONLY the courses table IN CASE of accidental * addition. @@ -1435,4 +1458,4 @@ exports.getNotifications = function(email, callback) { }); -} \ No newline at end of file +} -- cgit v1.2.3