nodes: 0, module; 1, function_definition; 2, function_name:find_one_and_delete; 3, parameters; 4, block; 5, identifier:self; 6, identifier:filter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:projection; 15, None; 16, identifier:sort; 17, None; 18, identifier:session; 19, None; 20, identifier:kwargs; 21, comment:"""Finds a single document and deletes it, returning the document.
  
            >>> db.test.count_documents({'x': 1})
            2
            >>> db.test.find_one_and_delete({'x': 1})
            {u'x': 1, u'_id': ObjectId('54f4e12bfba5220aa4d6dee8')}
            >>> db.test.count_documents({'x': 1})
            1
  
          If multiple documents match *filter*, a *sort* can be applied.
  
            >>> for doc in db.test.find({'x': 1}):
            ...     print(doc)
            ...
            {u'x': 1, u'_id': 0}
            {u'x': 1, u'_id': 1}
            {u'x': 1, u'_id': 2}
            >>> db.test.find_one_and_delete(
            ...     {'x': 1}, sort=[('_id', pymongo.DESCENDING)])
            {u'x': 1, u'_id': 2}
  
          The *projection* option can be used to limit the fields returned.
  
            >>> db.test.find_one_and_delete({'x': 1}, projection={'_id': False})
            {u'x': 1}
  
          :Parameters:
            - `filter`: A query that matches the document to delete.
            - `projection` (optional): a list of field names that should be
              returned in the result document or a mapping specifying the fields
              to include or exclude. If `projection` is a list "_id" will
              always be returned. Use a mapping to exclude fields from
              the result (e.g. projection={'_id': False}).
            - `sort` (optional): a list of (key, direction) pairs
              specifying the sort order for the query. If multiple documents
              match the query, they are sorted and the first is deleted.
            - `session` (optional): a
              :class:`~pymongo.client_session.ClientSession`.
            - `**kwargs` (optional): additional command arguments can be passed
              as keyword arguments (for example maxTimeMS can be used with
              recent server versions).
  
          .. versionchanged:: 3.6
             Added ``session`` parameter.
  
          .. versionchanged:: 3.2
             Respects write concern.
  
          .. warning:: Starting in PyMongo 3.2, this command uses the
             :class:`~pymongo.write_concern.WriteConcern` of this
             :class:`~pymongo.collection.Collection` when connected to MongoDB >=
             3.2. Note that using an elevated write concern with this command may
             be slower compared to using the default write concern.
  
          .. versionchanged:: 3.4
             Added the `collation` option.
          .. versionadded:: 3.0
  
          """; 22, assignment; 23, call; 24, subscript; 25, True; 26, attribute; 27, argument_list; 28, identifier:kwargs; 29, string; 30, identifier:self; 31, identifier:__find_and_modify; 32, identifier:filter; 33, identifier:projection; 34, identifier:sort; 35, keyword_argument; 36, dictionary_splat; 37, string_content:remove; 38, identifier:session; 39, identifier:session; 40, identifier:kwargs
code: def find_one_and_delete(self, filter,
                              projection=None, sort=None, session=None, **kwargs):
          """Finds a single document and deletes it, returning the document.
  
            >>> db.test.count_documents({'x': 1})
            2
            >>> db.test.find_one_and_delete({'x': 1})
            {u'x': 1, u'_id': ObjectId('54f4e12bfba5220aa4d6dee8')}
            >>> db.test.count_documents({'x': 1})
            1
  
          If multiple documents match *filter*, a *sort* can be applied.
  
            >>> for doc in db.test.find({'x': 1}):
            ...     print(doc)
            ...
            {u'x': 1, u'_id': 0}
            {u'x': 1, u'_id': 1}
            {u'x': 1, u'_id': 2}
            >>> db.test.find_one_and_delete(
            ...     {'x': 1}, sort=[('_id', pymongo.DESCENDING)])
            {u'x': 1, u'_id': 2}
  
          The *projection* option can be used to limit the fields returned.
  
            >>> db.test.find_one_and_delete({'x': 1}, projection={'_id': False})
            {u'x': 1}
  
          :Parameters:
            - `filter`: A query that matches the document to delete.
            - `projection` (optional): a list of field names that should be
              returned in the result document or a mapping specifying the fields
              to include or exclude. If `projection` is a list "_id" will
              always be returned. Use a mapping to exclude fields from
              the result (e.g. projection={'_id': False}).
            - `sort` (optional): a list of (key, direction) pairs
              specifying the sort order for the query. If multiple documents
              match the query, they are sorted and the first is deleted.
            - `session` (optional): a
              :class:`~pymongo.client_session.ClientSession`.
            - `**kwargs` (optional): additional command arguments can be passed
              as keyword arguments (for example maxTimeMS can be used with
              recent server versions).
  
          .. versionchanged:: 3.6
             Added ``session`` parameter.
  
          .. versionchanged:: 3.2
             Respects write concern.
  
          .. warning:: Starting in PyMongo 3.2, this command uses the
             :class:`~pymongo.write_concern.WriteConcern` of this
             :class:`~pymongo.collection.Collection` when connected to MongoDB >=
             3.2. Note that using an elevated write concern with this command may
             be slower compared to using the default write concern.
  
          .. versionchanged:: 3.4
             Added the `collation` option.
          .. versionadded:: 3.0
  
          """
          kwargs['remove'] = True
          return self.__find_and_modify(filter, projection, sort,
                                        session=session, **kwargs)