-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleserver.js
25 lines (24 loc) · 895 Bytes
/
simpleserver.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
var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
// Connection URL
var url = 'mongodb://localhost:27017/anupama';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
assert.equal(err, null);
console.log("Connected correctly to server");
var collection = db.collection("dishes");
collection.insertOne({ name: "Uthapizza", description: "test" }, function(err, result) {
assert.equal(err, null);
console.log("After Insert:");
console.log(result.ops);
collection.find({}).toArray(function(err, docs) {
assert.equal(err, null);
console.log("Found:");
console.log(docs);
db.dropCollection("dishes", function(err, result) {
assert.equal(err, null);
db.close();
});
});
});
});