Skip to content

Instantly share code, notes, and snippets.

View travispbrown's full-sized avatar

Travis P. Brown travispbrown

View GitHub Profile
@travispbrown
travispbrown / express-mongodb-get
Last active December 13, 2015 19:29
Short example of node.js Express method to GET resource data from MongoDB. This was just a snippet for my blog to illustrate the simplicity of getting data from MongoDB. Assume the data has already been validated, and DynamoDB connection established.
resource.get (req, res) ->
collection.findOne _id:new mongodb.ObjectID req.body.id, (error, object) =>
res.json 200, JSON.stringify object
@travispbrown
travispbrown / express-mongodb-post
Last active December 13, 2015 19:29
Short example of node.js Express method to POST resource data into MongoDB. This was just a snippet for my blog to illustrate the simplicity of using MongoDB. Assume the data has already been validated, and MongoDB connection established.
resource.post (req, res) ->
collection.insert req.body, safe:true, (error, data) ->
if !error?
res.end 201
@travispbrown
travispbrown / express-dynamodb-post
Last active December 13, 2015 18:39
Short example of node.js Express method to POST resource data into DynamoDB. This was just a snippet for my blog to illustrate the type of transformation DynamoDB requires. Assume the data has already been validated, and DynamoDB connection established.
resource.post (req, res) ->
params =
TableName: 'TableName'
Item:
'id':
S: req.body.id
'color':
S: req.body.color
'tags':
SS: req.body.tags