def update(self, spec, document, upsert=False, manipulate=False,<EOL>safe=True, multi=False, callback=None, **kwargs):
if not isinstance(spec, dict):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not isinstance(document, dict):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not isinstance(upsert, bool):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not isinstance(safe, bool):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if kwargs:<EOL><INDENT>safe = True<EOL><DEDENT>if safe and not callable(callback):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not safe and callback is not None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if callback:<EOL><INDENT>callback = functools.partial(self._handle_response, orig_callback=callback)<EOL><DEDENT>self.__limit = None<EOL>connection = self.__pool.connection()<EOL>try:<EOL><INDENT>connection.send_message(<EOL>message.update(self.full_collection_name, upsert, multi,<EOL>spec, document, safe, kwargs), callback=callback)<EOL><DEDENT>except:<EOL><INDENT>connection.close()<EOL>raise<EOL><DEDENT>
Update a document(s) in this collection.

        Raises :class:`TypeError` if either `spec` or `document` is
        not an instance of ``dict`` or `upsert` is not an instance of
        ``bool``. If `safe` is ``True`` then the update will be
        checked for errors, raising
        :class:`~pymongo.errors.OperationFailure` if one
        occurred. Safe updates require a response from the database,
        while normal updates do not - thus, setting `safe` to ``True``
        will negatively impact performance.

        There are many useful `update modifiers`_ which can be used
        when performing updates. For example, here we use the
        ``"$set"`` modifier to modify some fields in a matching
        document:

        .. doctest::

          >>> db.test.insert({"x": "y", "a": "b"})
          ObjectId('...')
          >>> list(db.test.find())
          [{u'a': u'b', u'x': u'y', u'_id': ObjectId('...')}]
          >>> db.test.update({"x": "y"}, {"$set": {"a": "c"}})
          >>> list(db.test.find())
          [{u'a': u'c', u'x': u'y', u'_id': ObjectId('...')}]

        If `safe` is ``True`` returns the response to the *lastError*
        command. Otherwise, returns ``None``.

        # Any additional keyword arguments imply ``safe=True``, and will
        # be used as options for the resultant `getLastError`
        # command. For example, to wait for replication to 3 nodes, pass
        # ``w=3``.

        :Parameters:
          - `spec`: a ``dict`` or :class:`~bson.son.SON` instance
            specifying elements which must be present for a document
            to be updated
          - `document`: a ``dict`` or :class:`~bson.son.SON`
            instance specifying the document to be used for the update
            or (in the case of an upsert) insert - see docs on MongoDB
            `update modifiers`_
          - `upsert` (optional): perform an upsert if ``True``
          - `manipulate` (optional): manipulate the document before
            updating? If ``True`` all instances of
            :mod:`~pymongo.son_manipulator.SONManipulator` added to
            this :class:`~pymongo.database.Database` will be applied
            to the document before performing the update.
          - `safe` (optional): check that the update succeeded?
          - `multi` (optional): update all documents that match
            `spec`, rather than just the first matching document. The
            default value for `multi` is currently ``False``, but this
            might eventually change to ``True``. It is recommended
            that you specify this argument explicitly for all update
            operations in order to prepare your code for that change.
          - `**kwargs` (optional): any additional arguments imply
            ``safe=True``, and will be used as options for the
            `getLastError` command

        .. _update modifiers: http://www.mongodb.org/display/DOCS/Updating

        .. mongodoc:: update