Created
April 13, 2017 02:26
-
-
Save boris/d4f61974111936561b86aa0eacd0a876 to your computer and use it in GitHub Desktop.
How many cups of coffee a day?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (ctx, done) { | |
var MongoClient = require('mongodb').MongoClient; | |
var assert = require('assert'); | |
var ObjectId = require('mongodb').ObjectID; | |
var url = ctx.data.MONGO_URL; | |
var insertValue = function(db) { | |
db.collection('cups').insertOne({ | |
'date': new Date(), | |
'coffee': 1 | |
}, function(err, result) { | |
assert.equal(err, null); | |
done(null, "New coffee added!"); | |
}); | |
}; | |
MongoClient.connect(url, function(err, db) { | |
assert.equal(null, err); | |
insertValue(db, function() { | |
db.close(); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment