简体   繁体   中英

Transactions In MongoDB

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.

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

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

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

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://stackoverflow.com/a/12757751/1173560

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM