Explicit and implicit collection/index creation inside transactions
Parent: Multi-Document Transactions · Published reference · snapshot 2026-10-31
↓ Facts as markdownall context files
Source-anchored research for Explicit and implicit collection/index creation inside transactions. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Problems, failure modes and limitations
- MongoDB 8.0 prohibits collection creation in a cross-shard write transaction, whether creation is explicit or implicit. Writing an existing collection on shard A and implicitly creating another collection on shard B cannot occur in the same transaction. Deployment on a sharded cluster alone is not the prohibition: the operations reference permits collection/index creation in a distributed transaction that is not a cross-shard write transaction. (medium confidence) (verified as of 2026-10-31) [source]
- HMRC associates pre-4.4 transactional implicit creation with error 263, OperationNotSupportedInTransaction, and the message Cannot create namespace ... in multi-document transaction; it recommends precreating the collection, especially in tests. Spring Data also recommends having required structures in place, but its blanket collection-creation prohibition does not describe the MongoDB 8.0 server eligibility rules. (medium confidence) (verified as of 2026-10-31) [source]
Facts and statements
- Collection creation in transactions became available with MongoDB 4.4. DRIVERS-706 identifies server compatibility 4.4; HMRC independently documents that implicit insert/upsert creation was unsupported before that release. (medium confidence) [source]
- For MongoDB 8.0, create/db.createCollection explicitly creates a collection in a transaction. An insert, or an update/findAndModify with upsert:true that inserts into an absent collection, can create it implicitly. (medium confidence) [source]
- In MongoDB 8.0, explicit collection or index creation requires transaction-level read concern local. Implicit collection creation may instead use any supported transaction read concern: local, majority, or snapshot. Index creation that also creates its absent collection still follows the explicit-index requirement. (medium confidence) [source]
- In MongoDB 8.0, a new index can target only an absent collection or an empty collection created earlier in that transaction. An already-existing empty collection does not qualify. The r8.0.0 implementation separately rejects new indexes on pre-existing collections and on non-empty newly created collections; inserting before building the new index therefore breaks eligibility. (medium confidence) (verified as of 2026-10-31) [source]
- MongoDB 8.0 allows createIndex()/createIndexes() to check an already existing index and return successfully without creating it. This does not authorize building a new index on an old collection: r8.0.0 checks indexesAlreadyExist before the branch that rejects new indexes on existing collections. (medium confidence) (verified as of 2026-10-31) [source]
Children
- No children recorded.