Last active
August 29, 2015 14:15
-
-
Save ssebro/c0c48b31a95ae3deff62 to your computer and use it in GitHub Desktop.
Upsert
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
adapter.update = function (model, id, update ,options) { | |
var _this = this; | |
model = typeof model == 'string' ? this.model(model) : model; | |
update = this._serialize(model, update); | |
return new Promise(function (resolve, reject) { | |
var cb = function (error, resource) { | |
if (error) { | |
return reject(error); | |
} | |
_this._handleWrite(model, resource, error, resolve, reject); | |
}; | |
if(options){ | |
model.findByIdAndUpdate(id, update, cb); | |
}else{ | |
model.findByIdAndUpdate(id, update, options, cb); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment