-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoMethod.js
63 lines (58 loc) · 1.39 KB
/
mongoMethod.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
56
57
58
59
60
61
62
63
import assert from "assert";
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://heroku_dkz7q79x:[email protected]:55684/heroku_dkz7q79x';
export const updateQuestion1 = (choice) => {
MongoClient.connect(url , (err, db) => {
assert.equal(null,err);
if (choice == "yes") {
db.collection('results').update(
{question : 1},
{$inc: {yes: 1}},
{upsert: true}
);
}
else {
db.collection('results').update(
{question : 1},
{$inc: {no: 1}},
{upsert: true}
);
}
db.close();
});
};
export const updateQuestion2 = (choice) => {
MongoClient.connect(url , (err, db) => {
assert.equal(null,err);
let obj = {$inc : {}};
obj["$inc"][choice] = 1;
db.collection('results').update(
{question : 2},
obj,
{upsert: true}
);
db.close();
});
};
export const updateInstagram = (list) => {
MongoClient.connect(url , (err, db) => {
assert.equal(null,err);
db.collection("instagram").update(
{
id: 1,
},
{
id : 1,
item : list
},
{upsert: true}
);
db.close();
});
};
export const getInstagram = async () => {
const db = await MongoClient.connect(url);
let docs = await db.collection('instagram').find({}).toArray();
let doc = docs[0];
return doc;
}