Skip to content

Commit

Permalink
Merge pull request #5 from makmonty/master
Browse files Browse the repository at this point in the history
Avoiding to set createdAt when the update already has set it by other way
  • Loading branch information
james075 committed May 4, 2020
2 parents 9693465 + 215e6cf commit 466aaed
Show file tree
Hide file tree
Showing 2 changed files with 809 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoose-createdat-updatedat.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function preQuerySaveHook(next, options) {
update[options.updatedAt] = currentDate;
}

if (options.createdAt) {
if (options.createdAt && !update[options.createdAt]) {
const setOnInsert = update.$setOnInsert || {};
setOnInsert[options.createdAt] = currentDate;
update.$setOnInsert = setOnInsert;
Expand Down
Loading

0 comments on commit 466aaed

Please sign in to comment.