Files
cgm-remote-monitor/tests
15a5fb24d3 fix(profile): use replaceOne upsert to prevent duplicate key error on save (#8455)
Regression from 286fa07 (switch profile api to new mongo driver) caused
E11000 duplicate key errors when saving an existing profile because
insertOne rejects documents whose _id already exists.

Changes:
- Replace insertOne with replaceOne({ _id }, obj, { upsert: true })
- Add try/catch for ObjectID construction to handle invalid/missing _id
- Use hasOwnProperty check for created_at to preserve explicit values

Tests added:
- save() updates existing profile by _id (from PR #8455)
- save() generates _id when none provided
- save() generates _id when invalid _id provided
- save() preserves explicit created_at without overwriting

Cherry-picked from AndyLow91/cgm-remote-monitor@55a70139 with
additional regression tests.

Closes nightscout/cgm-remote-monitor#8455

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-19 12:06:56 -07:00
..
2021-02-18 18:23:40 +02:00
2022-08-30 12:49:01 +03:00
2021-02-08 19:28:49 +02:00
2019-11-10 21:57:49 +00:00
2020-12-14 22:30:21 +02:00
2020-02-22 17:07:21 +02:00