Migrate mongodb code (not tested)