-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-1.js
37 lines (31 loc) · 941 Bytes
/
server-1.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
var mongoose = require('mongoose'),
assert = require('assert');
var Dishes = require('./models/dishes-1');
// 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 user
var newDish = Dishes({
name: 'Uthapizza',
description: 'Test'
});
// save the user
newDish.save(function(err) {
if (err) throw err;
console.log('Dish created!');
// get all the users
Dishes.find({}, function(err, dishes) {
if (err) throw err;
// object of all the users
console.log(dishes);
db.collection('dishes').drop(function() {
db.close();
});
});
});
});