'Dereference a :class:`~bson.dbref.DBRef`, getting the
document it points to.
Raises :class:`TypeError` if `dbref` is not an instance of
:class:`~bson.dbref.DBRef`. Returns a document, or ``None`` if
the reference does not point to a valid document.  Raises
:class:`ValueError` if `dbref` has a database specified that
is different from the current database.
:Parameters:
- `dbref`: the reference
- `**kwargs` (optional): any additional keyword arguments
are the same as the arguments to
:meth:`~pymongo.collection.Collection.find`.'

def dereference(self, dbref, **kwargs):

    if (not isinstance(dbref, DBRef)):
        raise TypeError(('cannot    dereference    a    %s' % type(dbref)))
    if ((dbref.database is not None) and (dbref.database != self.__name)):
        raise ValueError(('trying    to    dereference    a    DBRef    that    points    to    another    database    (%r    not    %r)' % (dbref.database, self.__name)))
    return self[dbref.collection].find_one({'_id': dbref.id}, **kwargs)
