-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyMongo.js
More file actions
37 lines (29 loc) · 782 Bytes
/
myMongo.js
File metadata and controls
37 lines (29 loc) · 782 Bytes
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
var mongodb = require('mongodb');
var exports = module.exports = {};
var MongoClient = mongodb.MongoClient;
var dbUrl = process.env.MONGOLAB_URI;
exports.addTerm = function(termObj, callback){
MongoClient.connect(dbUrl, (err, db) => {
if(err) throw err;
db.collection('searchTerms').insert(termObj, (err, data) => {
if(err) throw err;
db.close();
callback(null, "inserted!");
})
})
}
exports.getTerms = function(callback){
MongoClient.connect(dbUrl, (err, db) => {
if(err) throw err;
db.collection('searchTerms').find({
},{
_id: 0,
term: 1,
when: 1
}).sort({when: -1}).toArray((err, data) => {
if(err) throw err;
db.close();
callback(null, data);
})
})
}