Skip to content

Instantly share code, notes, and snippets.

@sunny1304
Created December 5, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunny1304/7806383 to your computer and use it in GitHub Desktop.
Save sunny1304/7806383 to your computer and use it in GitHub Desktop.
promise example for mongoose
var relationPromise = ArticleRelation.findOne({parentArticleGuid: oldArticle.guid}).exec();
relationPromise
.then(function(relation){
if (relation == null){
relation = new ArticleRelation({
parentArticleGuid: oldArticle.guid,
organization: task.organization._id
});
}
return relation;
}
.then(function(relation){
relation.save(function (error, articleRelation) {
if (error) {
throw error;
}
})
}, function(err){
throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment