nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key_or_list; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, return_statement; 13, identifier:direction; 14, None; 15, comment:"""Sorts this cursor's results.
  
          Pass a field name and a direction, either
          :data:`~pymongo.ASCENDING` or :data:`~pymongo.DESCENDING`::
  
              for doc in collection.find().sort('field', pymongo.ASCENDING):
                  print(doc)
  
          To sort by multiple fields, pass a list of (key, direction) pairs::
  
              for doc in collection.find().sort([
                      ('field1', pymongo.ASCENDING),
                      ('field2', pymongo.DESCENDING)]):
                  print(doc)
  
          Beginning with MongoDB version 2.6, text search results can be
          sorted by relevance::
  
              cursor = db.test.find(
                  {'$text': {'$search': 'some words'}},
                  {'score': {'$meta': 'textScore'}})
  
              # Sort by 'score' field.
              cursor.sort([('score', {'$meta': 'textScore'})])
  
              for doc in cursor:
                  print(doc)
  
          Raises :class:`~pymongo.errors.InvalidOperation` if this cursor has
          already been used. Only the last :meth:`sort` applied to this
          cursor has any effect.
  
          :Parameters:
            - `key_or_list`: a single key or a list of (key, direction)
              pairs specifying the keys to sort on
            - `direction` (optional): only used if `key_or_list` is a single
              key, if not given :data:`~pymongo.ASCENDING` is assumed
          """; 16, call; 17, assignment; 18, assignment; 19, identifier:self; 20, attribute; 21, argument_list; 22, identifier:keys; 23, call; 24, attribute; 25, call; 26, identifier:self; 27, identifier:__check_okay_to_chain; 28, attribute; 29, argument_list; 30, identifier:self; 31, identifier:__ordering; 32, attribute; 33, argument_list; 34, identifier:helpers; 35, identifier:_index_list; 36, identifier:key_or_list; 37, identifier:direction; 38, identifier:helpers; 39, identifier:_index_document; 40, identifier:keys
code: def sort(self, key_or_list, direction=None):
          """Sorts this cursor's results.
  
          Pass a field name and a direction, either
          :data:`~pymongo.ASCENDING` or :data:`~pymongo.DESCENDING`::
  
              for doc in collection.find().sort('field', pymongo.ASCENDING):
                  print(doc)
  
          To sort by multiple fields, pass a list of (key, direction) pairs::
  
              for doc in collection.find().sort([
                      ('field1', pymongo.ASCENDING),
                      ('field2', pymongo.DESCENDING)]):
                  print(doc)
  
          Beginning with MongoDB version 2.6, text search results can be
          sorted by relevance::
  
              cursor = db.test.find(
                  {'$text': {'$search': 'some words'}},
                  {'score': {'$meta': 'textScore'}})
  
              # Sort by 'score' field.
              cursor.sort([('score', {'$meta': 'textScore'})])
  
              for doc in cursor:
                  print(doc)
  
          Raises :class:`~pymongo.errors.InvalidOperation` if this cursor has
          already been used. Only the last :meth:`sort` applied to this
          cursor has any effect.
  
          :Parameters:
            - `key_or_list`: a single key or a list of (key, direction)
              pairs specifying the keys to sort on
            - `direction` (optional): only used if `key_or_list` is a single
              key, if not given :data:`~pymongo.ASCENDING` is assumed
          """
          self.__check_okay_to_chain()
          keys = helpers._index_list(key_or_list, direction)
          self.__ordering = helpers._index_document(keys)
          return self