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 },