-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (33 loc) · 1.35 KB
/
index.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
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const dboper = require('./operations');
const url = 'mongodb://localhost:27017/test';
MongoClient.connect(url).then((database) => {
const db = database.db("conFusion");
console.log('Connected correctly to mongo server');
dboper.insertDocuments(db, { name: "Vadonut", description: "Test"}, "dishes")
.then((result) => {
console.log("Insert Document:\n", result.ops);
return dboper.findDocuments(db, "dishes");
})
.then((docs) => {
console.log("Found Documents:\n", docs);
return dboper.updateDocument(db, { name: "Vadonut" },
{ description: "Updated Test" }, "dishes");
})
.then((result) => {
console.log("Updated Document:\n", result.result);
return dboper.findDocuments(db, "dishes");
})
.then((docs) => {
console.log("Found Updated Documents:\n", docs);
//return db.dropCollection("dishes");
return Promise.resolve("Db Closed<>!");
})
.then((result) => {
console.log("Dropped Collection: ", result);
return database.close();
})
.catch((err) => console.log(err));
})
.catch((err) => console.log(err));