-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-promos.js
55 lines (47 loc) · 1.55 KB
/
server-promos.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 Promos = require('./models/promotions');
// 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
Promos.create({
"name": "Weekend Grand Buffet",
"image": "images/buffet.png",
"label": "New",
"price": "19.99",
"description": "Featuring . . ."
}, function(err, promo) {
if (err) throw err;
console.log('Promo created!');
console.log(promo);
var id = promo._id;
// get all the dishes
setTimeout(function() {
Promos.findByIdAndUpdate(id, {
$set: {
description: 'Updated Test'
}
}, {
new: true
})
.exec(function(err, promo) {
if (err) throw err;
console.log('Updated Promo!');
console.log(promo);
promo.save(function(err, promo) {
console.log('Updated Promos!');
console.log(promo);
db.collection('promos').drop(function() {
db.close();
});
});
});
}, 3000);
});
});