D
D
Dmitrii Solovev2016-04-20 21:41:26
MongoDB
Dmitrii Solovev, 2016-04-20 21:41:26

How to make history in Mongodb...SQL?

There is a collection of invoices, with documents of this type:

{
  name: "Bank",
  summ: 1000
}

I want to display statistics (graph) by month. What is the state of the account, was it at 1.1, 1.2, .1.3, 1.4, .1.5 and so on.
Are there any triggers that, for example, push each first number into the history array, the current date and the amount?
What is the correct way to implement such a history in mongo?
How similar things are implemented in SQL DB?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2016-04-20
@k12th

Are there any triggers that, for example, push each first number into the history array, the current date and the amount?
This can be done with cron. But there's no point.
Usually they simply store the initial state of the account and all transactions; when necessary, they take this initial amount and "lose" all operations and get the current amount (of course, for speed, the current state can also be cached). People like to see the history of their account and understand where exactly such an amount came from.
In the same way, you can get account status for each month, just find all transactions from the account opening date to the last day of the previous month and “reproduce” them.
PS The algorithm does not change here, SQL or NoSQL.

S
Stanislav Makarov, 2016-04-21
@Nipheris

Theoretical part:
About SQL: The SQL:2011 Standard, Tools for Temporal Databases . While not supported by all vendors, but can be taken as a basis for writing a bicycle.
I won’t say much about Mongo, look at this:
https://github.com/thiloplanz/v7files/wiki/Vermongo
https://github.com/saintedlama/mongoose-version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question