Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Fix #15091

Summary

MongoDB does not allow multiple operations on a single transaction in parallel. Since Mongoose create() uses save() under the hood, Mongoose cannot reliably create() multiple docs in a transaction unless ordered: true is set.

Examples

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, tests require fixing:
Replicaset tests:

  1) transactions
       distinct (gh-8006):
     MongooseError: Cannot call `create()` with a session and multiple documents unless `ordered: true` is set
      at Function.create (lib/model.js:2623:11)
      at Context.<anonymous> (test/docs/transactions.test.js:347:21)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

  2) transactions
       throws error if using `create()` with multiple docs in a transaction (gh-15091):
     OverwriteModelError: Cannot overwrite `Test` model once compiled.
      at NativeConnection.model (lib/connection.js:1395:13)
      at conn.model (test/common.js:78:18)
      at Context.<anonymous> (test/docs/transactions.test.js:673:24)
      at process.processImmediate (node:internal/timers:491:21)

@vkarpov15 vkarpov15 added this to the 8.10 milestone Dec 16, 2024
@vkarpov15 vkarpov15 changed the base branch from master to 8.10 December 16, 2024 17:20
@vkarpov15
Copy link
Collaborator Author

Will merge this into 8.10 to be cautious

@vkarpov15 vkarpov15 merged commit b7191c4 into 8.10 Dec 16, 2024
74 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15091 branch December 17, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Given transaction number 1 does not match any in-progress transactions

3 participants