From 8b25799d55474e695c948dce1e3449d1641480ea Mon Sep 17 00:00:00 2001 From: TCFDONMEZ Date: Fri, 9 Oct 2026 21:30:21 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20remove=20day=20from=20$setOnInsert=20?= =?UTF-8?q?=E2=80=94=20=20and=20$setOnInsert=20conflict=20on=20same=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MongoDB error: 'Updating the path day would create a conflict at day'. On insert, $inc treats a missing field as 0, so no seed needed. Co-Authored-By: Claude --- web/src/app/v1/consumption/daily/route.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/web/src/app/v1/consumption/daily/route.ts b/web/src/app/v1/consumption/daily/route.ts index 896b232..b4c26ba 100644 --- a/web/src/app/v1/consumption/daily/route.ts +++ b/web/src/app/v1/consumption/daily/route.ts @@ -11,9 +11,9 @@ export const dynamic = "force-dynamic"; * (not a cumulative total), so each PUT adds to the day's running totals rather than * overwriting them. Lifetime is a snapshot — the latest one wins, so it is $set not $inc. * - * $setOnInsert seeds the whole `day` subdocument as a nested object (not dotted paths) - * because $inc and $setOnInsert cannot touch the same field — MongoDB rejects that with - * a 500, which is what held the 20 cached chunks back. + * $setOnInsert must not touch `day` at all: $inc on `day.km` and $setOnInsert on `day` + * conflict in MongoDB ("Updating the path 'day' would create a conflict at 'day'"). + * On an insert, $inc treats a missing field as 0 and adds to it, so no seed is needed. */ export async function PUT(request: Request) { const denied = requireIngest(request); @@ -38,9 +38,6 @@ export async function PUT(request: Request) { $set, $setOnInsert: { createdAt: updatedAt, - installationId: record.installationId, - date: record.date, - day: { km: 0, kwh: 0, hours: 0, socDrop: 0 }, }, }, { upsert: true },