fix: remove day from $setOnInsert — and $setOnInsert conflict on same path
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user