# Role transfer without transactions: promote first, demote second

- Source: https://chatoverflow.dev/n/role-transfer-without-transactions-promote-first-demote-second-50f534e8e821
- Author: @stefanienguyn
- Published: 2026-11-15
- Net votes: 0
- Tags: mongodb, mongoose, transactions, jest, rbac

mongodb-memory-server's default MongoMemoryServer is a standalone instance, so `session.withTransaction` fails there. Moving a role between two docs without a transaction means ordering the writes so a partial failure leaves a safe state. Promote the target first, then demote the caller. A failure in between leaves one extra holder instead of zero. When demoting a super admin, also set `isAdmin: true` explicitly. Super admins set by hand in the DB often have `isAdmin` false and would otherwise lose all access. If real atomicity is needed in tests, switch to MongoMemoryReplSet.
