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


Python helpers._fields_list_to_dict方法代码示例

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


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

示例1: __find_and_modify

# 需要导入模块: from pymongo import helpers [as 别名]
# 或者: from pymongo.helpers import _fields_list_to_dict [as 别名]
def __find_and_modify(self, filter: dict, projection: Optional[Union[list, dict]],
                                sort: Optional[List[tuple]], upsert: Optional[bool] = None,
                                return_document: bool = ReturnDocument.BEFORE, **kwargs) -> MutableMapping:
        """Internal findAndModify helper."""
        common.validate_is_mapping('filter', filter)
        if not isinstance(return_document, bool):
            raise ValueError('return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER')
        cmd = SON([('findAndModify', self.name),
                   ('query', filter),
                   ('new', return_document)])
        collation = validate_collation_or_none(kwargs.pop('collation', None))
        cmd.update(kwargs)
        if projection is not None:
            cmd['fields'] = helpers._fields_list_to_dict(projection, 'projection')
        if sort is not None:
            cmd['sort'] = helpers._index_document(sort)
        if upsert is not None:
            common.validate_boolean('upsert', upsert)
            cmd['upsert'] = upsert

        connection = await self.database.client.get_connection()
        if connection.max_wire_version >= 4 and 'writeConcern' not in cmd:
            wc_doc = self.write_concern.document
            if wc_doc:
                cmd['writeConcern'] = wc_doc

        out = await connection.command(
            self.database.name, cmd, ReadPreference.PRIMARY, self.codec_options,
            allowable_errors=[_NO_OBJ_ERROR], collation=collation
        )
        helpers._check_write_command_response([(0, out)])
        return out.get('value') 
开发者ID:ZeoAlliance,项目名称:aiomongo,代码行数:34,代码来源:collection.py

示例2: __init__

# 需要导入模块: from pymongo import helpers [as 别名]
# 或者: from pymongo.helpers import _fields_list_to_dict [as 别名]
def __init__(self, collection: 'aiomongo.Collection',
                 filter: Optional[dict] = None, projection: Optional[Union[dict, list]] = None,
                 skip: int = 0, limit: int = 0, sort: Optional[List[tuple]] = None,
                 modifiers: Optional[dict] = None, batch_size: int = 0, no_cursor_timeout: bool = False,
                 collation: Optional[Union[Collation, dict]]=None) -> None:

        spec = filter
        if spec is None:
            spec = {}
        validate_is_mapping('filter', spec)
        if not isinstance(skip, int):
            raise TypeError('skip must be an instance of int')
        if not isinstance(limit, int):
            raise TypeError('limit must be an instance of int')

        if modifiers is not None:
            validate_is_mapping('modifiers', modifiers)

        if not isinstance(batch_size, int):
            raise TypeError('batch_size must be an integer')
        if batch_size < 0:
            raise ValueError('batch_size must be >= 0')

        if projection is not None:
            if not projection:
                projection = {'_id': 1}
            projection = helpers._fields_list_to_dict(projection, 'projection')

        self.__id = None
        self.__codec_options = DEFAULT_CODEC_OPTIONS
        self.__collation = validate_collation_or_none(collation)
        self.__collection = collection
        self.__connection = None
        self.__data = deque()
        self.__explain = False
        self.__max_scan = None
        self.__spec = spec
        self.__projection = projection
        self.__skip = skip
        self.__limit = limit
        self.__batch_size = batch_size
        self.__modifiers = modifiers or {}
        self.__ordering = sort and helpers._index_document(sort) or None
        self.__hint = None
        self.__comment = None
        self.__max_time_ms = None
        self.__max_await_time_ms = None
        self.__max = None
        self.__min = None
        self.__killed = False

        self.__codec_options = collection.codec_options
        self.__read_preference = collection.read_preference
        self.__read_concern = collection.read_concern
        self.__retrieved = 0

        self.__query_flags = 0
        if self.__read_preference != ReadPreference.PRIMARY:
            self.__query_flags |= _QUERY_OPTIONS['slave_okay']
        if no_cursor_timeout:
            self.__query_flags |= _QUERY_OPTIONS['no_timeout'] 
开发者ID:ZeoAlliance,项目名称:aiomongo,代码行数:63,代码来源:cursor.py

示例3: group

# 需要导入模块: from pymongo import helpers [as 别名]
# 或者: from pymongo.helpers import _fields_list_to_dict [as 别名]
def group(self, key: Optional[Union[List[str], str, Code]], condition: dict, initial: int, reduce: str,
                    finalize: Optional[str] = None, **kwargs) -> List[MutableMapping]:
        """Perform a query similar to an SQL *group by* operation.

        Returns an array of grouped items.

        The `key` parameter can be:

          - ``None`` to use the entire document as a key.
          - A :class:`list` of keys (each a :class:`str`) to group by.
          - A :class:`str`, or :class:`~bson.code.Code` instance containing a JavaScript
            function to be applied to each document, returning the key
            to group by.

        The :meth:`group` method obeys the :attr:`read_preference` of this
        :class:`Collection`.

        :Parameters:
          - `key`: fields to group by (see above description)
          - `condition`: specification of rows to be
            considered (as a :meth:`find` query specification)
          - `initial`: initial value of the aggregation counter object
          - `reduce`: aggregation function as a JavaScript string
          - `finalize`: function to be called on each object in output list.
          - `**kwargs` (optional): additional arguments to the group command
            may be passed as keyword arguments to this helper method
        """
        group = {}
        if isinstance(key, str):
            group['$keyf'] = Code(key)
        elif key is not None:
            group = {'key': helpers._fields_list_to_dict(key, 'key')}
        group['ns'] = self.name
        group['$reduce'] = Code(reduce)
        group['cond'] = condition
        group['initial'] = initial
        if finalize is not None:
            group['finalize'] = Code(finalize)

        cmd = SON([('group', group)])
        collation = validate_collation_or_none(kwargs.pop('collation', None))
        cmd.update(kwargs)

        connection = await self.database.client.get_connection()

        return (await connection.command(
            self.database.name, cmd, self.read_preference, self.codec_options, collation=collation
        ))['retval'] 
开发者ID:ZeoAlliance,项目名称:aiomongo,代码行数:50,代码来源:collection.py


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