Fix sort of collection in database