SessionContext is not safe for use in goroutines - does this preclude unordered bulk writes?

Bulk operations can be run “unordered” which may result in parallel op execution (doc link).

mongo.SessionContext is not safe for use in concurrent code, however (doc link).

Does this mean I should not perform unordered bulk writes within transactions? Or does the mongo driver handle this and only goroutines generated by the user are unsafe?


No. mongodb officially supports bulk operations within transactions. It only means you shouldn’t use concurrent ops on the same session from your app.

parallel bulk operations is a server side thing and has nothing to do with that rule.

1 Like

Gotcha, I see where this is can be inferred now under “Error Handling inside Transactions” - they mention that the bulk write fails fast even when running unordered, which suggests its a supported operation like you say:

Inside a transaction, the first error in a bulk write causes the entire bulk write to fail and aborts the transaction, even if the bulk write is unordered.

Thanks for the link.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.