-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (44 loc) · 1.17 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
const mongoose = require('mongoose');
const Campsite = require('./models/campsite');
const url = 'mongodb://localhost:27017/nucampsite';
const connect = mongoose.connect(url, {
useCreateIndex: true,
useFindAndModify: false,
useNewUrlParser: true,
useUnifiedTopology: true
});
connect.then(() => {
console.log('Connected correctly to server');
Campsite.create({
name: 'React Lake Campground',
description: 'test'
})
.then(campsite => {
console.log(campsite);
return Campsite.findByIdAndUpdate(campsite._id, {
$set: { description: 'Updated Test Document' }
}, {
new: true
});
})
.then(campsite => {
console.log(campsite);
campsite.comments.push({
rating: 5,
text: 'What a magnificent view!',
author: 'Tinus Lorvaldes'
});
return campsite.save();
})
.then(campsite => {
console.log(campsite);
return Campsite.deleteMany();
})
.then(() => {
return mongoose.connection.close();
})
.catch(err => {
console.log(err);
mongoose.connection.close();
});
});