Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeaus/e05922f5c13278b8b6f7ae2f142a9104 to your computer and use it in GitHub Desktop.
Save lukeaus/e05922f5c13278b8b6f7ae2f142a9104 to your computer and use it in GitHub Desktop.
const _ = require('lodash')
const IRRELEVANT_PROPS_FOR_OBJECT_COMPARISON = ['__v', '_doc', '$__', '_id'];
/*
* Remove properties that you don't care about from a mongoose object
* to make comparing mongoose objects easy.
*/
omitIrrelevantMongoosePropertiesForObjComparison(obj) {
let relevantObjProps;
if (obj.schema && obj.schema.paths) {
relevantObjProps = _.omit(obj.schema.paths, IRRELEVANT_PROPS_FOR_OBJECT_COMPARISON);
} else {
relevantObjProps = _.omit(obj, IRRELEVANT_PROPS_FOR_OBJECT_COMPARISON);
}
return _.pick(obj, _.keys(relevantObjProps));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment