I have a python web application that connects to a MongoDB database. At the moment I only have a collection where I have a lot of documents. Users can edit these documents so I want to implement a history of changes. Actually I am only interested in storing the username and the edited fields (i.e. the old value and the new value). So, I was thinking of creating a new collection called "change_history" and store there all the change history, using manually the reference to the _id of the document. A record of that collection would look something like this:
{
_id: "12345"
document_id: "456d"
date_change: "2023-01-01"
username: "jane"
color: {last_field: "blue", new_field: "red"}
}
So, later on when you want to consult the changes of a document you would have to filter the collection "change_history" according to the document_id. I could even sort them by date. Is this a good approach in terms of practicality and efficiency? I don't know if there is a mongo tool for python that does this automatically. Or if I should in the other collection group them by document_id. One of the limitations I have is that I don't know yet the requirement of how users will be able to see this in the frontend.