Created
December 5, 2013 14:56
-
-
Save sunny1304/7806383 to your computer and use it in GitHub Desktop.
promise example for mongoose
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
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