Skip to content

Instantly share code, notes, and snippets.

@percyperez
Created May 23, 2014 21:18
Show Gist options
  • Save percyperez/034a2c2ca66603fcf67e to your computer and use it in GitHub Desktop.
Save percyperez/034a2c2ca66603fcf67e to your computer and use it in GitHub Desktop.
Get populated data from subdocument excluding specific fields
var populate_data_from = 'trainers tags',
video_data = {
path: 'videos',
model: 'Video',
select: 'title description legacy_video videofiles.sources.10'
},
excludes = '-royalties';
/**
* @return {object} A single collection with videos, tags and trainers
* populated based on a partnumber
*/
VideoCollection.statics.FindByPartNumber = function(partnumber, callback) {
this.findOne({'partnumber': partnumber}).select(excludes).populate(populate_data_from).populate(video_data).exec(callback);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment