fine-tuned data engine. MongoDB legacy

def _run_custom_data_engine(self, start_id_obj, end_id_obj, start_timeperiod, end_timeperiod):
        """ fine-tuned data engine. MongoDB legacy """
        collection_name = context.process_context[self.process_name].source
        iteration = 0
        while True:
            cursor = self.ds.cursor_fine(collection_name,
                                         start_id_obj,
                                         end_id_obj,
                                         iteration,
                                         start_timeperiod,
                                         end_timeperiod)

            if iteration == 0 and cursor.count(with_limit_and_skip=True) == 0:
                msg = 'No entries in {0} at range [{1} : {2}]'.format(collection_name, start_id_obj, end_id_obj)
                self.logger.warning(msg)
                break

            start_id_obj = None
            for document in cursor:
                start_id_obj = document['_id']
                self._process_single_document(document)
                self.performance_tracker.increment_success()
            if start_id_obj is None:
                break
            iteration += 1

        self._cursor_exploited()
        msg = 'Cursor exploited after {0} iterations'.format(iteration)
        self.logger.info(msg)