mongodb
mongodb copied to clipboard
Support Mongodb 4.0 transactions
Support transactions in mongodb elixir driver. The end goal is to see many to many joins working in mongodb ecto.
EXAMPLE FROM MONGODB DOCUMENTATION
Consider a scenario where for each order shipment, you need to decrease the inventory for the item shipped. If either write fails, you want the undo both operations.
The following Python code shows a sample usage of transactions where either both write operations succeed or both operations fail.
client = pymongo.MongoClient(...)
db = client.test
s = client.start_session()
s.start_transaction()
try:
db.inventory.update_one({"sku": "abc123"}, {"$inc": {"qty": -100}}, session=s)
db.shipment.insert_one({"sku": "abc123", "qty": 100}, session=s)
except Exception:
s.abort_transaction()
else:
s.commit_transaction()
s.end_session()
As mentioned in: https://github.com/ankhers/mongodb_ecto/issues/113
https://github.com/mongodb/mongo/releases/tag/r4.0.0-rc5 Is the latest release candidate.
Mongdb tests for transactions https://github.com/mongodb/mongo/blob/v4.0/jstests/core/txns/multi_statement_transaction.js
Requires session support. https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency
Going to take a break but the session and transaction example is https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/examples/example-transaction.c .
Any news on this one?
Nothing yet.
I want to try to implement this one.
That would be appreciated. Thank you!
My idea is to automatically start session for each new connection, always (or maybe make that optional via connection options) and then use regular DBConnection API to handle transactions. The only issue I see there is that when there will be pool then the application will not provide linearity. However that shouldn't be much of issue as this is how the library behaves currently.
Close as current master has support for sessions and transactions (not implemented as above, but with their own custom API).
For getting this transaction changes. In my local, i tried with "{:mongodb, "~> 0.5.1"}". But i can't able to get the transaction futures like. Mongo.start_session or Session.start_transaction(session). How can i get transaction future
@YasirAsar It's only on master at this point.