Fix bug causing mongoengine TypeError when max_results>500.