def dereference(self, dbref: DBRef, **kwargs) -> MutableMapping:
"""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:`~aiomongo.collection.Collection.find`.
"""
if not isinstance(dbref, DBRef):
raise TypeError('cannot dereference a {}'.format(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 ({} not {})'.format(dbref.database, self.name))
return await self[dbref.collection].find_one({'_id': dbref.id}, **kwargs)
评论列表
文章目录