code: def _apply_sort(cursor, sort_by, sort_direction):
          if sort_direction is not None and sort_direction.lower() == "desc":
              sort = pymongo.DESCENDING
          else:
              sort = pymongo.ASCENDING
          return cursor.sort(sort_by, sort)