database.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号