Last active
August 29, 2015 13:56
-
-
Save knubie/8907481 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@update = (collection, query, field, update) -> | |
# Set up this object to pass in to the mongo update method. | |
$set = {} | |
# Create the $set object for mongo's update method by passing | |
# the doc's 'field' to the 'update' argument. | |
$set[field] = _.compose(update, _.reduce) field.split('.') | |
, (memo, accessor) -> memo[accessor] # Get field from the doc. | |
, collection.findOne(query) | |
# Update the mongo collection. | |
collection.update query, {$set} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment