当前位置: 首页>>代码示例>>Python>>正文


Python cursor.Cursor方法代码示例

本文整理汇总了Python中pymongo.cursor.Cursor方法的典型用法代码示例。如果您正苦于以下问题:Python cursor.Cursor方法的具体用法?Python cursor.Cursor怎么用?Python cursor.Cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.cursor的用法示例。


在下文中一共展示了cursor.Cursor方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: distinct

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def distinct(self, key):
        """Get a list of distinct values for `key` among all documents
        in this collection.

        Raises :class:`TypeError` if `key` is not an instance of
        :class:`basestring` (:class:`str` in python 3).

        To get the distinct values for a key in the result set of a
        query use :meth:`~pymongo.cursor.Cursor.distinct`.

        :Parameters:
          - `key`: name of key for which we want to get the distinct values

        .. note:: Requires server version **>= 1.1.0**

        .. versionadded:: 1.1.1
        """
        return self.find().distinct(key) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:collection.py

示例2: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, collection, filter=None, skip=0, limit=0,
                 no_cursor_timeout=False, sort=None, batch_size=0,
                 session=None):
        """Create a new cursor, similar to the normal
        :class:`~pymongo.cursor.Cursor`.

        Should not be called directly by application developers - see
        the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead.

        .. versionadded 2.7

        .. mongodoc:: cursors
        """
        # Hold on to the base "fs" collection to create GridOut objects later.
        self.__root_collection = collection

        super(GridOutCursor, self).__init__(
            collection.files, filter, skip=skip, limit=limit,
            no_cursor_timeout=no_cursor_timeout, sort=sort,
            batch_size=batch_size, session=session) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:grid_file.py

示例3: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, collection, filter=None, skip=0, limit=0,
                 no_cursor_timeout=False, sort=None, batch_size=0):
        """Create a new cursor, similar to the normal
        :class:`~pymongo.cursor.Cursor`.

        Should not be called directly by application developers - see
        the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead.

        .. versionadded 2.7

        .. mongodoc:: cursors
        """
        # Hold on to the base "fs" collection to create GridOut objects later.
        self.__root_collection = collection

        super(GridOutCursor, self).__init__(
            collection.files, filter, skip=skip, limit=limit,
            no_cursor_timeout=no_cursor_timeout, sort=sort,
            batch_size=batch_size) 
开发者ID:leancloud,项目名称:satori,代码行数:21,代码来源:grid_file.py

示例4: list

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def list(
        self,
        model: MongoDBModel,
        session: ClientSession = None,
        _offset: int = 0,
        _limit: int = 0,
        _sort: list = None,
        **kwargs
    ) -> Cursor:
        _id = kwargs.pop("id", notset)
        if _id != notset:
            kwargs["_id"] = _id

        collection_name = model.get_db_collection()
        collection = self.get_collection(collection_name)
        return collection.find(
            kwargs, session=session, skip=_offset, limit=_limit, sort=_sort
        ) 
开发者ID:identixone,项目名称:fastapi_contrib,代码行数:20,代码来源:client.py

示例5: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, collection, filter=None, skip=0, limit=0,
                 no_cursor_timeout=False, sort=None, batch_size=0,
                 session=None):
        """Create a new cursor, similar to the normal
        :class:`~pymongo.cursor.Cursor`.

        Should not be called directly by application developers - see
        the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead.

        .. versionadded 2.7

        .. mongodoc:: cursors
        """
        collection = _clear_entity_type_registry(collection)

        # Hold on to the base "fs" collection to create GridOut objects later.
        self.__root_collection = collection

        super(GridOutCursor, self).__init__(
            collection.files, filter, skip=skip, limit=limit,
            no_cursor_timeout=no_cursor_timeout, sort=sort,
            batch_size=batch_size, session=session) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:24,代码来源:grid_file.py

示例6: count

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def count(self):
        """Get the number of documents in this collection.

        To get the number of documents matching a specific query use
        :meth:`pymongo.cursor.Cursor.count`.
        """
        return self.find().count() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:collection.py

示例7: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, collection, spec=None, skip=0, limit=0,
                 timeout=True, sort=None, max_scan=None,
                 read_preference=None, tag_sets=None,
                 secondary_acceptable_latency_ms=None, compile_re=True):
        """Create a new cursor, similar to the normal
        :class:`~pymongo.cursor.Cursor`.

        Should not be called directly by application developers - see
        the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead.

        .. versionadded 2.7

        .. mongodoc:: cursors
        """
        # Hold on to the base "fs" collection to create GridOut objects later.
        self.__root_collection = collection

        # Copy these settings from collection if they are not set by caller.
        read_preference = read_preference or collection.files.read_preference
        tag_sets = tag_sets or collection.files.tag_sets
        latency = (secondary_acceptable_latency_ms
                   or collection.files.secondary_acceptable_latency_ms)

        super(GridOutCursor, self).__init__(
            collection.files, spec, skip=skip, limit=limit, timeout=timeout,
            sort=sort, max_scan=max_scan, read_preference=read_preference,
            secondary_acceptable_latency_ms=latency, compile_re=compile_re,
            tag_sets=tag_sets) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:grid_file.py

示例8: apply_form_field_names

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def apply_form_field_names(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        def _get_decoded_record(record):
            if isinstance(record, dict):
                for field in record:
                    if isinstance(record[field], list):
                        tmp_items = []
                        items = record[field]
                        for item in items:
                            tmp_items.append(_get_decoded_record(item))
                        record[field] = tmp_items
                    if field not in field_names.values() and \
                            field in field_names.keys():
                        record[field_names[field]] = record.pop(field)
            return record

        cursor = func(*args, **kwargs)
        if isinstance(cursor, Cursor) and 'id_string' in kwargs and\
                'username' in kwargs:
            username = kwargs.get('username')
            id_string = kwargs.get('id_string')
            dd = XForm.objects.get(
                id_string=id_string, user__username=username)
            records = []
            field_names = dd.data_dictionary().get_mongo_field_names_dict()
            for record in cursor:
                records.append(_get_decoded_record(record))
            return records
        return cursor
    return wrapper 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:33,代码来源:decorators.py

示例9: test_read_all

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def test_read_all(monkeypatch, adapter):
    assert isinstance(adapter.read(), MongoCursor) 
开发者ID:christabor,项目名称:flask_jsondash,代码行数:4,代码来源:test_mongo_adapter.py

示例10: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, document_cls, cursor, *args, **kwargs):
        # Such a cunning plan my lord !
        # We inherit from Cursor but don't call it __init__ because
        # we act as a proxy to the underlying raw_cursor
        WrappedCursor.raw_cursor.__set__(self, cursor)
        WrappedCursor.document_cls.__set__(self, document_cls) 
开发者ID:Scille,项目名称:umongo,代码行数:8,代码来源:pymongo.py

示例11: __init__

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def __init__(self, *args):
        self.selected_columns: Optional[ColumnSelectConverter] = None
        self.where: Optional[WhereConverter] = None
        self.joins: List[
            U[InnerJoinConverter, OuterJoinConverter]
        ] = []
        self.order: Optional[OrderConverter] = None
        self.offset: Optional[OffsetConverter] = None
        self.limit: Optional[LimitConverter] = None
        self.distinct: Optional[DistinctConverter] = None
        self.groupby: Optional[GroupbyConverter] = None
        self.having: Optional[HavingConverter] = None

        self._cursor: Optional[U[BasicCursor, CommandCursor]] = None
        super().__init__(*args) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:query.py

示例12: count

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def count(self):

        if self._cursor is None:
            self._cursor = self._get_cursor()
        return len(list(self._cursor))
        # if isinstance(self._cursor, BasicCursor):
        #     return self._cursor.count()
        # else:
        #     return len(list(self._cursor)) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:query.py

示例13: custom_json_serializer

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def custom_json_serializer(obj):
    if isinstance(obj, bson.objectid.ObjectId):
        return str(obj)
    elif isinstance(obj, datetime.datetime):
        return pytz.timezone('UTC').localize(obj).isoformat()
    elif isinstance(obj, Job):
        return obj.map()
    elif isinstance(obj, Cursor):
        return list(obj)
    raise TypeError(repr(obj) + " is not JSON serializable") 
开发者ID:scitran,项目名称:core,代码行数:12,代码来源:encoder.py

示例14: collect_pymongo_metrics

# 需要导入模块: from pymongo import cursor [as 别名]
# 或者: from pymongo.cursor import Cursor [as 别名]
def collect_pymongo_metrics(context, trace, instance, response):
    from pymongo.cursor import Cursor
    from pymongo.results import (
        BulkWriteResult,
        DeleteResult,
        InsertOneResult,
        InsertManyResult,
        UpdateResult,
    )

    command, key = None, None

    for command_name, key_attr, result_type in [
        ("bulk_write", "inserted_count", BulkWriteResult),
        ("delete", "deleted_count", DeleteResult),
        ("insert_one", "inserted_id", InsertOneResult),
        ("insert_many", "inserted_ids", InsertManyResult),
        ("update", ("upserted_id", "modified_count"), UpdateResult),
    ]:
        if isinstance(response, result_type):
            command = command_name
            if isinstance(key_attr, tuple):
                for attr in key_attr:
                    key = getattr(response, attr, None)
                    if key is not None:
                        break
            else:
                key = getattr(response, key_attr, None)
            if key is not None:
                key = str(key)
            break

    if isinstance(response, Cursor):  # pragman: no cover
        command = "find"
        key = response.retrieved

    hostname, port = None, None

    database = getattr(instance, "database", None)
    if database is not None:
        address = getattr(database, "address", None)
        if address is not None:
            hostname, port = address

    request = Request(
        command=ensure_utf8(command),
        key=ensure_utf8(key),
        hostname=ensure_utf8(hostname),
        port=ensure_utf8(port),
        connectionName=None,
        db=ensure_utf8(getattr(database, "name", None)),
        table=ensure_utf8(getattr(instance, "name", None)),
    )
    request = request._asdict()
    context.iopipe.mark.db_trace(trace, "mongodb", request) 
开发者ID:iopipe,项目名称:iopipe-python,代码行数:57,代码来源:auto_db.py


注:本文中的pymongo.cursor.Cursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。