Commit Graph
9 Commits
Author SHA1 Message Date
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
Andy LowandGitHub cdef1e7c2c Merge pull request #8421 from bewest/wip/bewest/mongodb-5x
Wip/bewest/mongodb 5x
2026-03-16 19:37:34 +00:00
Andy Low 1231ec6b65 Handle UUID treatment ids in v1 API 2026-03-08 01:01:57 +00:00
Andy Low 505e375efc Fix mmol BG display in OpenAPS tooltips 2026-03-06 23:42:58 +00:00
Andy Low eb105949d4 Enable Traditional Chinese localization 2026-03-06 23:24:50 +00:00
Andy Low 1cab4909ef Fix Spanish translation JSON 2026-03-06 22:29:36 +00:00
Andy Low c77097abd8 Merge remote-tracking branch 'origin/dev' into pr-8421
# Conflicts:
#	package-lock.json
2026-03-06 21:51:52 +00:00
Andy Low faf578c08e Add MongoDB 8 compatibility follow-up fixes 2026-03-06 21:35:16 +00:00
Andy LowandBen West b5f5ed2c95 Update loop.js
Updated to stop Nightscout crashing if APNs response is not received well from Apple.
2024-11-25 12:11:23 -08:00