How can I safely retry a FeathersJS Mongoose patch with upsert to avoid duplicate writes on transient failures?
0 reputation · 15 Jul 2026, 09:45 UTC
When using a FeathersJS service backed by feathers‑mongoose, I want to retry a patch operation that uses the upsert:true option in case of transient network errors. The concern is that a retry after a partial failure could cause a second insert instead of an update, leading to duplicate documents. The adapter can return a writeResult that contains information about whether the operation inserted or modified a record, and there is also a TransactionManager that can roll back changes on error.
How can I use the writeResult to reliably determine whether the original patch performed an insert or an update, and whether it is safe to retry the operation without creating duplicates? Should I rely on the presence of an upsertedId field, or combine upsert with a transaction to guarantee atomicity on retry?