From 46f5af098764ab16732542f5c4305366ffe094d1 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 24 Feb 2026 10:49:34 +0100 Subject: [PATCH] [docstore] fix evaluating dollar based references (#31792) Co-authored-by: Brian Gough GitOrigin-RevId: 8ffc1d1f930d0ac3c68cd59d8412932fea4229cd --- services/docstore/app/js/MongoManager.js | 3 +- .../test/unit/js/MongoManager.test.js | 32 +++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/services/docstore/app/js/MongoManager.js b/services/docstore/app/js/MongoManager.js index 0650c5b9e0..9064294222 100644 --- a/services/docstore/app/js/MongoManager.js +++ b/services/docstore/app/js/MongoManager.js @@ -100,7 +100,8 @@ function convertUpdateToPipeline(update) { // $unset uses a different schema in a pipeline pipeline.push({ [operation]: field }) } else { - pipeline.push({ [operation]: { [field]: value } }) + // Avoid evaluating '$foo' strings + pipeline.push({ [operation]: { [field]: { $literal: value } } }) } } } diff --git a/services/docstore/test/unit/js/MongoManager.test.js b/services/docstore/test/unit/js/MongoManager.test.js index 45dd8ff51f..3ad3f8c505 100644 --- a/services/docstore/test/unit/js/MongoManager.test.js +++ b/services/docstore/test/unit/js/MongoManager.test.js @@ -56,9 +56,9 @@ describe('MongoManager', () => { } const pipeline = ctx.MongoManager.convertUpdateToPipeline(update) expect(pipeline).to.deep.equal([ - { $set: { lines: ['foo', 'bar'] } }, - { $set: { ranges: { comments: [] } } }, - { $set: { rev: 42 } }, + { $set: { lines: { $literal: ['foo', 'bar'] } } }, + { $set: { ranges: { $literal: { comments: [] } } } }, + { $set: { rev: { $literal: 42 } } }, { $unset: 'inS3' }, ]) }) @@ -243,8 +243,8 @@ describe('MongoManager', () => { project_id: new ObjectId(ctx.projectId), rev: ctx.oldRev, }) - assert.equal(args[1][0].$set.lines, ctx.lines) - assert.equal(args[1][1].$set.rev, ctx.oldRev + 1) + assert.equal(args[1][0].$set.lines.$literal, ctx.lines) + assert.equal(args[1][1].$set.rev.$literal, ctx.oldRev + 1) }) it('should fallback on mismatch', async ctx => { @@ -418,16 +418,8 @@ describe('MongoManager', () => { rev: ctx.archivedDoc.rev, }, [ - { - $set: { - lines: ctx.archivedDoc.lines, - }, - }, - { - $set: { - ranges: ctx.archivedDoc.ranges, - }, - }, + { $set: { lines: { $literal: ctx.archivedDoc.lines } } }, + { $set: { ranges: { $literal: ctx.archivedDoc.ranges } } }, { $unset: 'inS3' }, ] ) @@ -482,14 +474,12 @@ describe('MongoManager', () => { [ { $set: { - lines: ctx.archivedDoc.lines, - }, - }, - { - $set: { - ranges: {}, + lines: { + $literal: ctx.archivedDoc.lines, + }, }, }, + { $set: { ranges: { $literal: {} } } }, { $unset: 'inS3' }, ] )