-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainRepository.js
More file actions
59 lines (51 loc) · 1.49 KB
/
DomainRepository.js
File metadata and controls
59 lines (51 loc) · 1.49 KB
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
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
function get() {
return new Promise(async (resolve, reject) => {
const client = new MongoClient(url);
try {
await client.connect();
const db = client.db("domains")
const ilCollection = db.collection('co.il').find();
resolve(await ilCollection.toArray());
client.close();
} catch (ex) {
reject(ex);
}
})
}
function getOne(id) {
return new Promise(async (resolve, reject) => {
const client = new MongoClient(url);
try {
await client.connect();
const db = client.db("domains")
const item = db.collection('co.il').findOne({ _id: id });
resolve(item);
client.close();
} catch (ex) {
reject(ex);
}
})
}
function update(id, entity) {
return new Promise(async (resolve, reject) => {
const client = new MongoClient(url);
try {
await client.connect();
const db = client.db("domains")
const item = db.collection('co.il').findOneAndReplace({ _id: id }, entity);
resolve(item);
client.close();
} catch (ex) {
reject(ex);
}
})
}
// get().then(res => console.log(res));
// getOne('ckmisrael.co.il').then(res => console.log(res));
module.exports = {
get: get,
getOne: getOne,
update: update
}