N
N
Nikita Shuklin2016-07-04 17:12:37
MongoDB
Nikita Shuklin, 2016-07-04 17:12:37

How to do stack completion in MongoDb?

The crux of the matter is as follows. We know that there are no transactions in monge. In my project, there can be no deadlocks and other nonsense, but each operation is associated with the creation of 5-6 records in the database, from which I ask the question, is there any mechanism to continue performing operations if the server crashes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kano, 2016-07-14
@Kano

There is a template that allows you to simulate the operation of transactions. In the documentation for mongo, it is described here https://docs.mongodb.com/manual/tutorial/perform-t...
The method describes a simple scenario, but gives a general idea of ​​​​how it should work.
True, there is no solution with data versioning (what the client will receive while the "transaction" is being executed)

N
napa3um, 2016-07-14
@napa3um

If the partial presence or absence of data in different collections can break the business logic, then a two-phase commit is implemented ( https://docs.mongodb.com/manual/tutorial/perform-t...), or choose a transactional database. However, there is often no such problem, and pre-created documents in separate collections do not affect the business logic until they are referenced in some "master document" (for example, until the newly created customer falls into the order, which must be created after all "subordinate" documents as a fact of processing the user's request). It is better not to "complete" requests after the server crash, but rather to ignore "hanging" records. And you can start a kind of garbage collector that cleans up garbage without the necessary links (run once when the database starts, or only when it starts after an emergency stop). Do not plan for database failure as the main request processing scenario,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question