-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-leaders.js
55 lines (47 loc) · 1.58 KB
/
server-leaders.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
var mongoose = require('mongoose'),
assert = require('assert');
var Leaders = require('./models/leadership');
// Connection URL
var url = 'mongodb://localhost:27017/anupama';
mongoose.connect(url);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
console.log("Connected correctly to server");
// create a new dish
Leaders.create({
"name": "Peter Pan",
"image": "images/alberto.png",
"designation": "Chief Epicurious Officer",
"abbr": "CEO",
"description": "Our CEO, Peter, . . ."
}, function(err, leader) {
if (err) throw err;
console.log('Leader created!');
console.log(leader);
var id = leader._id;
// get all the dishes
setTimeout(function() {
Leaders.findByIdAndUpdate(id, {
$set: {
description: 'Updated Test'
}
}, {
new: true
})
.exec(function(err, leader) {
if (err) throw err;
console.log('Updated Leader!');
console.log(leader);
leader.save(function(err, leader) {
console.log('Updated Leader!');
console.log(leader);
db.collection('leaders').drop(function() {
db.close();
});
});
});
}, 3000);
});
});