Skip to content

Instantly share code, notes, and snippets.

@ssebro
Last active August 29, 2015 14:15
Show Gist options
  • Save ssebro/c0c48b31a95ae3deff62 to your computer and use it in GitHub Desktop.
Save ssebro/c0c48b31a95ae3deff62 to your computer and use it in GitHub Desktop.
Upsert
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