Skip to content

Instantly share code, notes, and snippets.

@talesluna-zz
Created September 12, 2017 11:29
Show Gist options
  • Save talesluna-zz/eccd810912d224fc78847bb0fb33da07 to your computer and use it in GitHub Desktop.
Save talesluna-zz/eccd810912d224fc78847bb0fb33da07 to your computer and use it in GitHub Desktop.
Mongoose Merge Update with Lodash
import _ from 'lodash';
class MergeUpdate {
save(original, update) {
// Update timestamp manually
if (original.updatedAt) {
update.updatedAt = new Date().toISOString();
}
// Merge objects
_.merge(original, update);
// Save document
return original.save();
}
}
export default new MergeUpdate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment