Rewrite using mongoengine