Created
February 8, 2014 21:52
-
-
Save ghostbar/8890898 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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