Created
June 14, 2019 01:41
-
-
Save lukeaus/e05922f5c13278b8b6f7ae2f142a9104 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
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