From b3df8c153bfca4e4a7a4260401693f2b0ceb069b Mon Sep 17 00:00:00 2001 From: brunodomenget Date: Wed, 4 Mar 2020 22:16:24 -0500 Subject: [PATCH 1/2] 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). --- lib/datastore.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/datastore.js b/lib/datastore.js index 4b978ad3..3a273070 100755 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -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 }); } From 3ad68e5129c778af70509950e7f5efacdbd05e87 Mon Sep 17 00:00:00 2001 From: brunodomenget Date: Wed, 4 Mar 2020 22:22:46 -0500 Subject: [PATCH 2/2] Update datastore.js Removed unnecessary comment --- lib/datastore.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/datastore.js b/lib/datastore.js index 3a273070..8c50a073 100755 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -619,9 +619,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { modifiedDoc = model.modify(candidates[i], updateQuery); if (self.timestampData) { modifiedDoc.createdAt = createdAt; - //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 no updatedAt date is present, using the current time if (updateQuery.$set.updatedAt === undefined) { modifiedDoc.updatedAt = new Date(); }