-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpost.js
More file actions
35 lines (31 loc) · 810 Bytes
/
post.js
File metadata and controls
35 lines (31 loc) · 810 Bytes
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
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var url = 'mongodb://localhost:27017/Blog';
module.exports = {
addPost: function(title, subject, callback){
MongoClient.connect(url, function(err, db) {
db.collection('post').insertOne( {
"title": title,
"subject": subject
},function(err, result){
assert.equal(err, null);
console.log("Saved the blog post details.");
if(err == null){
callback(true)
}
else{
callback(false)
}
});
});
},
getPost: function(callback){
MongoClient.connect(url, function(err, db){
db.collection('post', function (err, collection) {
collection.find().toArray(function (err, list) {
callback(list);
});
});
})
}
}