Created
February 18, 2015 00:24
-
-
Save ssebro/cff61f3b88c0096644c5 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.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