-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.js
42 lines (42 loc) · 1.33 KB
/
queries.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
"use strict"
const mongo = require('mongodb').MongoClient;
function storeval(term) {
mongo.connect(process.env.MONGOLOGIN, conn);
function conn(err, client) {
if (err) {
throw err;
}
else {
var db = client.db("gotohell");
var collectn = db.collection("image_search");
collectn.findOne({}, (e, result) => {
if (e) throw e;
result = result.value;
let datestring = new Date().toString();
result.push({ "term": term, "when": datestring });
if (result.length > 10) {
result.shift();
}
collectn.update({}, { $set: { "value": result } });
client.close();
});
}
}
}
function resultFn(res) {
let returnval=[];
mongo.connect(process.env.MONGOLOGIN, conn);
function conn(err, client) {
if (err) {
throw err;
}
else {
var db = client.db("gotohell");
var collectn = db.collection("image_search"); collectn.findOne({}, (e, result) => {
if (e) throw e;
res.json(result.value.reverse());
});
}
}
}
module.exports = { "store": storeval ,"resultFn":resultFn};