Python + MongoDB document versioning

python tutorial
python download
python ide
python online
python basic
what is python used for
python wiki
python from scratch

I have an app in the works for use internally as a project/task tracker in the company that I'm working for. Playing around with MongoDB atm. I have the following pseudo-schema in mind:

task
    _id
    name
    project
    initial_notes
    versions
        number
        versions
            version_1
                worker
                status
                date(if submitted)
                review_notes(if rejected)
                reply_on(if accepted/rejected)
            (version_n)(if any)

The problem that I'm having is with versioning the task. I've read a number of possible ways but I'm falling short of understanding them all the way through. I read something that I liked here and really like the way mongoid does it's versioning

Thinking of it better I'd rather have it something like this

task
    _id
    versions
        number_of_versions: 3
        current_version
            version_no: 3
            worker: bob
            status: accepted
        old_versions
            version
                version_no: 2
                worker: bob

I would like to show the most recent version only when displaying a collection of tasks and I would like to show all versions of a particular task when entering the detailed information page for that particular task. Would this structure work? If yes, what would be some queries needed to run in order to achieve what I need?

Thank you in advance for your time reading this and maybe answering it. status: rejected version version_no: 1 worker: smith status: rejected


Yes, why not. That scheme would work. Also, have you considered something like this:

task 
    ...
    versions = [       # MongoDB array 
        {   version_id 
            worker
            status
            date(if submitted)
            review_notes(if rejected)
            reply_on(if accepted/rejected)
        },
        { version_id : ... }, 
        ... 

Possible version insertion query:

tasks.update( { # a query to locate a particular task}, 
              { '$push' : { 'versions', { # new version } } } )

Note, that retrieving the last version from the versions array in this case is done by the program, not by Mongo.

Python (programming language), Microsoft open-sources Lumos, a Python library for automatically monitoring web app metrics This Python For Beginners Course Teaches You The Python Language Fast. Join Over 50 Million Students Already Learning Online With Udemy


You might also consider a model like this:

task
    _id
    ...
    old_versions [
        {
            retired_on
            retired_by
            ...
        }
    ]

This has the advantage that your current data is always at the top level (you don't need to track the current version explicitly, the document is its own current version), and you can easily track history by taking the current version, removing the old_versions field, and $pushing it to the old_versions field in the db.

Since you seemed to want to minimize network IO, this also lets you easily avoid loading the old_versions when you don't need them:

> db.tasks.find({...}, {old_versions: 0})

You could also get fancier and store a list of old versions only of fields that have changed. This requires more delicate code in your application layer, and may not be necessary if you don't expect many revisions or for these documents to be very large.

Python Tutorial, Learn Python 2. Learn the basics of the world's fastest growing and most popular programming language used by software engineers, analysts, data scientists,  Python knows the usual control flow statements that other languages speak — if, for, while and range — with some of its own twists, of course. More control flow tools in Python 3 Python is a programming language that lets you work quickly and integrate systems more effectively.


JPMorgan's Python training guide for analysts and traders, The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google  The Python web site provides a Python Package Index (also known as the Cheese Shop, a reference to the Monty Python script of that name). There is also a search page for a number of sources of Python-related information. Failing that, just Google for a phrase including


Microsoft open-sources Lumos, a Python library for automatically monitoring web app metrics, learnpython.org is a free interactive Python tutorial for people who want to learn Python, fast. Python is a programming language. Python can be used on a server to create web applications. Start learning Python now »


Python may get pattern matching syntax, Outside of high-income countries Python is still the fastest growing major programming language; it simply started at a lower level and the growth  Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side), software development, mathematics, system scripting.


Learn Python 2, Python is a general-purpose interpreted, interactive, object-oriented, and high-​level programming language. It was created by Guido van Rossum during 1985-​  Note that Python 3.6.10 cannot be used on Windows XP or earlier. No files for this release. Python 3.5.9 - Nov. 2, 2019. Note that Python 3.5.9 cannot be used on Windows XP or earlier. No files for this release. Python 3.5.8 - Oct. 29, 2019. Note that Python 3.5.8 cannot be used on Windows XP or earlier. No files for this release. Python 2.7.17