Refactoring mongodb code to be in mongoengine handler as well as be async