What’s your new year’s resolution? One of mine is to be more active in helping and mentoring new Pythonistas, which is why I wrote the twitter bot behind @PythonQuestions. Inspired by the @MongoQuestion twitter bot, @PythonQuestions tweets new Stack Overflow questions tagged “Python”.
Posts about mongodb
In a question on StackOverflow a few days ago, a user was asking how to ensure that a document hasn’t changed between when a client read the document and wrote to it. If user A reads the document and makes some changes (through a web form, for instance), the change should be accepted if and only if no other user B has updated the document since when user A read the document.
MongoDB doesn’t support transactions, and even if it did, they wouldn’t help in this case. An assumption underlying the question is that the time between any given user’s reads and writes is long — otherwise explicit/pessimistic locking would be the simplest solution — in which case holding a transaction open on a traditional database server would be prohibitively costly (in terms of resource usage and performance).
The solution is to leverage MongoDB’s atomic update semantics with an optimistic concurrency solution. This comprises four basic steps: 1. read a document; 2. modify the document (i.e. present it to the user in a web form); 3. validate that the document hasn’t changed; 4. commit or abandon the user’s update. For anyone who’s used a source code version control system before, these steps should be familiar (i.e. pull, work locally, commit, and push for git users).
I presented Professor, my MongoDB profile viewer and analyzer, this past Tuesday at the New York MongoDB User Group. Professor aims to use the new features in the MongoDB 2.0 profiler to make profile information intelligible and actionable. It’s open-source (BSD-licensed) and written in Python and Flask.
One of my favorite features in MongoDB 2.0 is the finer-grained output of the database profiler. In earlier versions, the bulk of the profile information was contained within a (structured, parseable) string, but as of 2.0 the fields have been broken out and made queryable.
I’ve wanted to start writing a blog for the past few months. By which I mean, writing blog posts. But why focus on writing great content when you can write great software instead?