Skip to content

Instantly share code, notes, and snippets.

@Pokom
Created August 1, 2017 12:02
Show Gist options
  • Save Pokom/3bf3122b53d6ccef7dea1db0650f8354 to your computer and use it in GitHub Desktop.
Save Pokom/3bf3122b53d6ccef7dea1db0650f8354 to your computer and use it in GitHub Desktop.
Example of a virtual on a mongoose object
AssetsSchema.virtual('test').get(function () {
return Object.keys(this.licenseNode).reduce(({ prev, key }) => {
if (typeof this.licenseNode[key] === Number && this.licenseNode[key] > 0) {
prev[key] = this.licenseNode[key];
}
return prev;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment