Adventures with minimongo
[caption id=”attachment_802” align=”alignright” width=”240”] Too many choices! https://flic.kr/p/5zVmy5[/caption] Over the last few years I have wound up using mongo as my data store on several projects. In fact, it has been a while since I have written any SQL! For my latest project I again reached for mongo to hold my data, but this time I decided to use the Python minimongo project as my ODM (Object Document Mapper).
What is minimongo?
An ODM is to no-SQL what an ORM (Object Relation Model) is to a SQL database. For Python, minimongo is a small lightweight wrapper around mongo. Minimongo is built on top of pymongo which is a leading ODM in the python world. The main appeal of mongo is its ease of use. Python minimongo also has this, particularly if you are already familiar with mongo’s query syntax. My favorite feature is how you can access the fields in your document. Minimongo provides the traditional dict-like access, but it also provides field-like access! Here’s an example:
So what’s the downside?
Being a layer on top of a library has its advantages and disadvantages. With minimongo the biggest disadvantage I’ve run across so far is with authentication. In my production environment I’m using a username and password. Which is security 101. The issue is that when I establish my connection to the database it doesn’t seem to invoke the auth() command. So when my first call to mongo happens, it fails. The solution is pretty simple, it is adding a call to Document.auth() right after the connection is made. But… that also feels like a huge hack. Calling the connection() should in my opinion do the auth for you. After all, you are connecting! This seems to be an issue with pymongo, and since minimongo rides on top of it, that’s where I’m seeing the issue. It is a quirk, but comparatively it is not the worst thing in the world. And since my needs are rather modest in this project, this isn’t a showstopper. One more interesting feature: no schema declaration. You just define a class and map it to the collection in mongo and then go. It is an interesting approach. My data schema is in flux a little bit, so having this flexibility is pretty useful right now. I can go do whatever, and minimongo just goes with the flow. How this will work once I hit production might be another story though. I am a huge fan of declaring your types.
In conclusion: Try python minimongo
In the world of the startup MVP, ease of development is king. Minimongo is a very useful tool to help you get up and running fast. Try it out and let me know what you think!tags: