Skip to content

Instantly share code, notes, and snippets.

@boris
Created April 13, 2017 02:26
Show Gist options
  • Save boris/d4f61974111936561b86aa0eacd0a876 to your computer and use it in GitHub Desktop.
Save boris/d4f61974111936561b86aa0eacd0a876 to your computer and use it in GitHub Desktop.
How many cups of coffee a day?
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