question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using mongodb session transaction

See original GitHub issue

Hello,

I want to use transaction based on Umongo document instance, could we use a custom session in the commit method?

The following is the way that I use on the motor without Umongo:

async with await db_client.start_session() as session:
    async with session.start_transaction():
        session.collection.insert_one({myobject:"objectvalue"})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
lafrechcommented, Apr 16, 2020

Mongo 4 introduces transactions. We use it in our application. To do so we had to override a lot of methods in pymongo driver to pass session through all methods. (About 300 LoC.)

We did it in a clumsy way. It could probably be achieved more elegantly. Perhaps using context variables.

I’m open to the idea. Just never got the time to do it correctly enough to merge it in umongo.

0reactions
lafrechcommented, Nov 16, 2020

BTW, thanks @touilleMan for suggesting the use of context variables for this at PyConFR 2019.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session.startTransaction() — MongoDB Manual
Starts a multi-document transaction associated with the session. At any given time, you can have at most one open transaction for a session....
Read more >
How To Use Transactions in MongoDB - DigitalOcean
Begin by opening two separate MongoDB shell sessions. One will be used to execute commands in the transaction, and the other will allow...
Read more >
MongoDB Transactions - How to Use and Manage Them
MongoDB transactions exist within sessions. You create a session using startSession() and follow with session.startTransaction() to stage your transaction ...
Read more >
Sessions and Transactions - GitHub Pages
A session is used to group together a series of operations that are related to each other and should be executed with the...
Read more >
Getting Started with MongoDB Transactions on Single Nodes ...
Begin by launching two MongoDB shell sessions. One will be used to execute transaction commands, while the other will allow you to see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found