-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (43 loc) · 1.41 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
47
48
49
50
51
52
53
54
55
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const Dishes = require('./models/dishes');
const url = 'mongodb://localhost:27017/conFusion';
const connect = mongoose.connect(url, {
//not needed anymore with mongoose 5.x
//useMongoClient: true
});
connect.then(() => {
console.log('Connected correctlty to mongo server');
Dishes.create({
name: "Uthapizza",
description: "test",
}).then((dish) => {
console.log('saved the dish:\n');
console.log(dish);
return Dishes.findByIdAndUpdate(dish._id,{
$set: {description: "Updatedt Test"}
},{new: true}).exec();
}).then((dish) => {
console.log('updated dish:\n');
console.log(dish);
dish.comments.push({
rating: 5,
comment: "I \'m getting hungry!",
author: "Adam Bezecny"
});
return dish.save();
}).then((dish) => {
console.log("Updated dish with comment:\n");
console.log(dish);
return mongoose.connection.db.dropCollection('dishes');
//return Promise.resolve();
}).then(() => {
console.log('collection dropped');
return mongoose.connection.close();
}).then(() => {
console.log('mongo connection closed');
}).catch((err) => {
console.log('error occured:\n');
console.log(err);
});
});