Skip to content

Instantly share code, notes, and snippets.

@ssebro
Created February 18, 2015 00:24
Show Gist options
  • Save ssebro/cff61f3b88c0096644c5 to your computer and use it in GitHub Desktop.
Save ssebro/cff61f3b88c0096644c5 to your computer and use it in GitHub Desktop.
Upsert
adapter.upsert = function (model, id, update) {
var _this = this;
model = typeof model == 'string' ? this.model(model) : model;
update = this._serialize(model, update);
return new Promise(function (resolve, reject) {
model.findByIdAndUpdate(id, update,{upsert:true}, function (error, resource) {
if (error) {
return reject(error);
}
_this._handleWrite(model, resource, error, resolve, reject);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment