Skip to content

Commit

Permalink
fix(update): correctly apply timestamps to update pipelines
Browse files Browse the repository at this point in the history
Fix #11151
  • Loading branch information
vkarpov15 committed Jan 14, 2022
1 parent 4f64a14 commit 36a9232
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/update/applyTimestampsToUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function applyTimestampsToUpdate(now, createdAt, updatedAt, currentUpdate, optio

if (Array.isArray(updates)) {
// Update with aggregation pipeline
updates.push({ $set: { updatedAt: now } });
updates.push({ $set: { [updatedAt]: now } });

return updates;
}
Expand Down
15 changes: 15 additions & 0 deletions test/helpers/update.applyTimestampsToUpdate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const applyTimestampsToUpdate = require('../../lib/helpers/update/applyTimestampsToUpdate');
const assert = require('assert');

describe('applyTimestampsToUpdate', function() {
it('handles update pipelines (gh-11151)', function() {
const update = [{ $set: { title: 'mongoose-with-aggregate-set' } }];
const now = new Date('2016-01-01');
const res = applyTimestampsToUpdate(now, 'created_at', 'updated_at', update, {});

assert.equal(res.length, 2);
assert.equal(res[1].$set.updated_at.valueOf(), now.valueOf());
});
});

0 comments on commit 36a9232

Please sign in to comment.