Adding mongoengine.

Adapting the code to work with mongoengine.