code: def _get_ordering(son):
      
      def fmt(field, direction):
          return '{0}{1}'.format({-1: '-', 1: '+'}[direction], field)
  
      if '$orderby' in son:
          return ', '.join(fmt(f, d) for f, d in son['$orderby'].items())
docs: Helper function to extract formatted ordering from dict.