-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (33 loc) · 1.34 KB
/
app.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
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const { debugPort } = require('process');
const dboper = require('./operation');
const url = 'mongodb://localhost:27017/';
const dbname = 'complete_backend';
MongoClient.connect(url).then((client) => {
console.log('Connected correctly to server');
const db = client.db(dbname);
dboper.insertDocument(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");
})
.then((result) => {
console.log("Dropped Collection: ", result);
return client.close();
})
.catch((err) => console.log(err));
})
.catch((err) => console.log(err));