Skip to content

Instantly share code, notes, and snippets.

@ghostbar
Created February 8, 2014 21:52
Show Gist options
  • Select an option

  • Save ghostbar/8890898 to your computer and use it in GitHub Desktop.

Select an option

Save ghostbar/8890898 to your computer and use it in GitHub Desktop.
SchemaName.findOne({
_id: TheObjectId
}).lean().exec(theExtenderFunction); /* the .lean() is to make it JSON and modifiable */
function theExtenderFunction (err, firstResponse) {
if (err)
throw err; /* please handle your errors */
AnotherSchema.findOne({
_id: firstResponse.theOtherObjectId
}).exec(function (error, secondResponse) {
if (error)
throw error; /* remember, handle your errors! */
/* if you are using lodash or underscore, this is advisable:
_.extend(firstResponse, {
theOtherObjectId: secondResponse
});
*/
/* without underscore or lodash */
firstResponse['theOtherObjectId'] = secondResponse;
/* That will substitute firstResponse.theOtherObjectId with secondResponse data */
/* now you can send firstResponse */
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment