Transactions In MongoDB
Asked Answered
U

4

10

I am using a NoSQL database MongoDB with Java and Spring Data. I am aware that MongoDB only supports transactions for a single document.

I am using Spring Transactions to carry out MongoDB transcations. I am using TransactionTemplate. What should I set in TransactionManager when using TransactionTemplate?

EDIT

I have something like this:

<bean id=”txtTemplateBean” class=”org.springframework.transaction.support.TransactionTemplate”>
<property name=”transactionManager” ref=”txnManagerBean”></property>

I need to define txnManagerBean to point to something like DataSourceTransactionManager for a MongoDB database.

Unijugate answered 19/2, 2013 at 21:37 Comment(3)
What have you got so far?Mcintire
Nothing so far. I need a DataSourceTransactionManager or something similar for MongoDB. Google doesn`t return much. Any ideas?Unijugate
Please see edit aboveUnijugate
F
6

Multi-document ACID transactions are now supported in MongoDB 4.0! See https://www.mongodb.com/blog/post/mongodb-multi-document-acid-transactions-general-availability

Flyover answered 18/2, 2018 at 17:7 Comment(3)
Landing... RC0 is out - mongodb.com/download-center#developmentFlyover
Transactions have arrived. 4.0 has GA'ed. mongodb.com/blog/post/…Flyover
MongoDB 4.2 now supports distributed transactions in sharded clusters. mongodb.com/blog/post/…Flyover
R
5

MongoDB does support transaction-like semantics using two-phase commits.

There is also another independent effort to support transactions in mongodb using optimistic locking.

Rhpositive answered 22/5, 2013 at 18:0 Comment(1)
This answer is outdated. MongoDB4.0 now supports ACID transactions.Flyover
D
1

MongoDB doesn't support transactions, it only supports atomic operations.

http://docs.mongodb.org/manual/tutorial/model-data-for-atomic-operations/

Here is a post from someone who implemented transactions for MongoDB with optimistic locking: https://mcmap.net/q/160694/-mongodb-transactions-in-net-in-2010

Dragline answered 20/3, 2013 at 10:35 Comment(1)
Not true anymore.Flyover
A
0

Earlier I had doubts on MongoDB transactions, but by various articles at MongoDB web site, StackOverflow, and on-premises experiments, I have managed to get multi-document transactions working. I have reported the experiments in following tutorial drafts, to which I hope to get corrections from more experienced MongoDB users:

MongoDB Transactions Part I - Standalone

MongoDB Transactions Part II - ReplicaSet

MongoDB Transactions Part III - FailoverTests

On failover cases the MongoDB drivers reconnect client connections automatically to the new primary node, but interrupted transactions need to be restarted by clients – or not? From client point of view, elapsed time in failover is sometimes much shorter than the technical time of 2 second heartbeat time + 10 second wait time on primary’s response time. What is the explanation? Also some failover types fail to continue the replication process, which is fatal for the applications.

Alena answered 14/5, 2024 at 17:14 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.