MongoEngine 0.5 Released!

Hurray! MongoEngine 0.5 has finally been released!

With many improvements and bug fixes means that MongoEngine is more powerful than ever!

Core improvements include:

  • Efficient save
    Now when you save an existing object it atomically updates only what has been changed. Making it super efficient and so easy to use, without having to worrying about race conditions.
  • Efficient Database Referencing
    MongoEngine saves you queries by intelligently identifiying and dereferencing DBReference fields.
  • Complex fields
    Dictionary and List fields can store any complex data you require; other dictionaries, lists and other documents.
  • Signal support
    pre and post save / delete.
  • Subfield slicing
    For retrieving parts of subsets of lists, keeping data transfer down.
  • Abstract Base Classes
    Helps keep your document definitions dry so you can easily extend Documents.
  • Custom Object Managers
    When used with Astract Base Classes you can easily apply behaviour across all querysets.
  • query_counter
    A context manager, that helps you determine the cost of some queries / code - great for testing!

If you are using Flask - then check out our Flask-MongoEngine library, which provides MongoEngine connection and WTForms support.

With Multi Database support coming quickly in 0.6, we promise it wont take so long between release cycles!  Checkout the documentation to get you started!

 

Locking Django management commands

I have a number of management commands running via cron and sometimes they take longer to run than the time imbetween jobs. I don't want two jobs runningin parallel so when I saw that Django Notification used lock files in its emission of notices, I wanted to apply that cleanly to my management commands.

So I created a decorator that would add a locking file based on the current module file name, which would ensure that there is only ever one process running at any time. Then all I have to do is simply decorate my management commands by applying the decorator to the handle method like so:

# load the deocrator
from decorators import handle_lock
    
class Command(BaseCommand):
    help = "Regular Management command."
   
    # decorate the handle
    @handle_lock
    def handle(self, *args, **options):
        # Do your stuff here

 

And volia the management command will only ever run in single file. Go ahead and try it out: