Skip to content

Commit

Permalink
Merge pull request #39 from t27/master
Browse files Browse the repository at this point in the history
fix to make the URL and data keys optional during update
  • Loading branch information
edwardhotchkiss committed Oct 23, 2015
2 parents 1a17c14 + bcc823e commit 9d4796b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/short.js
Expand Up @@ -90,8 +90,13 @@ exports.retrieve = function(hash) {
exports.update = function(hash, updates) {
var promise = new Promise();
ShortURL.findOne({hash: hash}, function(err, doc) {
doc.URL = updates.URL;
doc.data = extend(doc.data, updates.data);
if (updates.URL) {
doc.URL = updates.URL;
}
if (updates.data) {
doc.data = extend(doc.data, updates.data);
doc.markModified('data'); //Required by mongoose, as data is of Mixed type
}
doc.save(function(err, updatedObj, numAffected) {
if (err) {
promise.reject(new Error('MongoDB - Cannot save updates'), true);
Expand Down

0 comments on commit 9d4796b

Please sign in to comment.