<!-- llms-explorer concept facts · https://llms-explorer.com/tree/explicit-and-implicit-collection-index-creation-inside-transactions/ · pack 2026-10-31 · ~881 tokens -->

# Explicit and implicit collection/index creation inside transactions

> Source-anchored research for Explicit and implicit collection/index creation inside transactions. Run status: COMPLETED.

Parent: [Multi-Document Transactions](https://llms-explorer.com/tree/multi-document-transactions/) · 2 facets · 7 facts · page: https://llms-explorer.com/tree/explicit-and-implicit-collection-index-creation-inside-transactions/

## 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](https://www.mongodb.com/docs/v8.0/core/transactions-operations/)
- 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](https://github.com/hmrc/hmrc-mongo)

## 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](https://jira.mongodb.org/browse/DRIVERS-706)
- 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](https://www.mongodb.com/docs/v8.0/core/transactions-operations/)
- 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](https://www.mongodb.com/docs/v8.0/reference/read-concern/)
- 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](https://www.mongodb.com/docs/v8.0/core/transactions-operations/)
- 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](https://www.mongodb.com/docs/v8.0/core/transactions/)
