-
Notifications
You must be signed in to change notification settings - Fork 2
/
questionDao.js
executable file
·55 lines (43 loc) · 1.57 KB
/
questionDao.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var monk = require ("monk");
var db = monk ("mongodb://IbmCloud_1140l45k_8qs5ds2q_sufis1th:[email protected]:41190/IbmCloud_1140l45k_8qs5ds2q");
var putQuestion = function(questionData, callback) {
var questionCol = db.get("question");
questionData.timestamp = new Date().getTime();
questionCol.insert(questionData, function (error, response) {
callback(response);
});
};
var getQuestions = function(filter, callback) {
var questionCol = db.get("question");
console.log("printing the filter for the getQuestions:");
console.log(filter);
var filterJson = {};
if(filter && filter.category){
filterJson = {category : filter.category};
}
questionCol.find(filterJson, {sort : { category : 1 }}, function (error, questionsList) {
callback(questionsList);
});
};
var getLastQuestion = function(filter, callback) {
var questionCol = db.get("question");
console.log("printing the filter for the getLastQuestion:");
console.log(filter);
var filterJson = {};
if(filter && filter.category){
filterJson = {category : filter.category};
}
questionCol.find(filterJson, {sort : { timestamp : -1 }, "limit" : 1}, function (error, lastQuestion) {
callback(lastQuestion);
});
};
var deleteQuestions = function(filter, callback) {
var questionCol = db.get("question");
questionCol.drop(function (error, questionsList) {
callback(questionsList);
});
};
module.exports.putQuestion = putQuestion;
module.exports.getQuestions = getQuestions;
module.exports.deleteQuestions = deleteQuestions;
module.exports.getLastQuestion = getLastQuestion;