I am using mongoose over mongodb.
In a request and response from nodejs express server, generally requires a no of queries to mongodb through mongoose.
In many cases it may happen, if first a few queries executes successfully and rest all failed under a transaction.
Now i need to rollback my db state to the very initial state of db.
So how can i rollback efficiently in mongodb? Please provide some suitable references.
Changed in version 4.0. Starting in version 4.0, MongoDB has no limit on the amount of data that can be rolled back. In previous versions, a mongod instance will not roll back more than 300 megabytes of data and requires manual intervention if more than 300 megabytes of data need to be rolled back.
Rollback Data Collection This is done by ensuring rollback files are created (only available with MongoDB version 4.0) by enabling the createRollbackDataFiles. By default this option is set to true hence rollback files will always be created. The rollback files are placed in the path /rollback/ .
Transactions use the transaction-level write concern to commit the write operations. Write operations inside transactions must be issued without explicit write concern specification and use the default write concern. At commit time, the writes are then commited using the transaction-level write concern.
MongoDB uses multi-granularity locking [1] that allows operations to lock at the global, database or collection level, and allows for individual storage engines to implement their own concurrency control below the collection level (e.g., at the document-level in WiredTiger).
I agree with Hector. If you need multiple document transactions then Mongo might not be a good fit for you. Can you embed your data structure in a single document? Then you can get the rollback you are looking for.
Another option is to look at the Mongo clone TokuMX which provides transactions across multiple documents.
Going through mongo tutorials
Here is a link i found for making two phase commits ( may be it is not guaranteed ) :
http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With