Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep existing updated at #629

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update datastore.js
Contrary to what is stated in the doc, updatedAt is always set to new Date() on document update, even if an updatedAt value is present in the request. I added an 'if' statement that changes that behaviour and keeps the request updatedAt value if present (this is necessary for synchronization mechanism).
brunodomenget authored Mar 5, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b3df8c153bfca4e4a7a4260401693f2b0ceb069b
7 changes: 6 additions & 1 deletion lib/datastore.js
Original file line number Diff line number Diff line change
@@ -619,7 +619,12 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
modifiedDoc = model.modify(candidates[i], updateQuery);
if (self.timestampData) {
modifiedDoc.createdAt = createdAt;
modifiedDoc.updatedAt = new Date();
//Update BD 2020-03-03 :
//Contrary to what is stated in the doc, updatedAt is always set to new Date() on document update, even if an updatedAt value is present in the request
// Adding the following 'if' statement changes that behaviour and keeps the request updatedAt value if present (this is necessary for synchronization mechanism)
if (updateQuery.$set.updatedAt === undefined) {
modifiedDoc.updatedAt = new Date();
}
}
modifications.push({ oldDoc: candidates[i], newDoc: modifiedDoc });
}