'Returns an instance of :class:`~bson.dbref.DBRef` useful in
`__raw__` queries.'

def to_dbref(self):

    if (self.pk is None):
        msg = 'Only    saved    documents    can    have    a    valid    dbref'
        raise OperationError(msg)
    return DBRef(self.__class__._get_collection_name(), self.pk)
