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


Python pymongo.IndexModel方法代码示例

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


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

示例1: parse_index

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import IndexModel [as 别名]
def parse_index(index, base_compound_field=None):
    keys = None
    args = {}
    if isinstance(index, IndexModel):
        keys = index.document['key'].items()
        args = {k: v for k, v in index.document.items() if k != 'key'}
    elif isinstance(index, (tuple, list)):
        # Compound indexes
        keys = [explicit_key(e) for e in index]
    elif isinstance(index, str):
        keys = [explicit_key(index)]
    elif isinstance(index, dict):
        assert 'key' in index, 'Index passed as dict must have a `key` entry'
        assert hasattr(index['key'], '__iter__'), '`key` entry must be iterable'
        keys = [explicit_key(e) for e in index['key']]
        args = {k: v for k, v in index.items() if k != 'key'}
    else:
        raise TypeError('Index type must be <str>, <list>, <dict> or <pymongo.IndexModel>')
    if base_compound_field:
        keys.append(explicit_key(base_compound_field))
    return IndexModel(keys, **args) 
开发者ID:Scille,项目名称:umongo,代码行数:23,代码来源:indexes.py

示例2: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import IndexModel [as 别名]
def __init__(self, function_result_status_persistance_conf, queue_name):
        self.function_result_status_persistance_conf = function_result_status_persistance_conf
        if self.function_result_status_persistance_conf.is_save_status:
            task_status_col = self.mongo_db_task_status.get_collection(queue_name)
            # params_str 如果很长,必须使用TEXt或HASHED索引。
            task_status_col.create_indexes([IndexModel([("insert_time_str", -1)]), IndexModel([("insert_time", -1)]),
                                            IndexModel([("params_str", pymongo.TEXT)]), IndexModel([("success", 1)])
                                            ], )
            task_status_col.create_index([("utime", 1)],
                                         expireAfterSeconds=function_result_status_persistance_conf.expire_seconds)  # 只保留7天。
            self._mongo_bulk_write_helper = MongoBulkWriteHelper(task_status_col, 100, 2)
            self.task_status_col = task_status_col 
开发者ID:ydf0509,项目名称:distributed_framework,代码行数:14,代码来源:base_consumer.py

示例3: test_init_index_compatibility

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import IndexModel [as 别名]
def test_init_index_compatibility(self):
        collection = self.db['canaries']
        collection.create_indexes([IndexModel([('id', ASCENDING)])])
        existing_indexes = collection.index_information()
        self.assertNotIn('unique', existing_indexes['id_1'])
        MongoStore(self.db_hosts, self.db_name, None, None)
        new_existing_indexes = collection.index_information()
        self.assertTrue(new_existing_indexes['id_1']['unique'])
        # For code coverage, testing when is_unique is already True as it
        # should be.
        MongoStore(self.db_hosts, self.db_name, None, None) 
开发者ID:quantopian,项目名称:coal-mine,代码行数:13,代码来源:test_mongo_store.py

示例4: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import IndexModel [as 别名]
def __init__(self):
        clinet = pymongo.MongoClient("localhost", 27017)
        db = clinet["PornHub"]
        self.PhRes = db["PhRes"]
        idx = IndexModel([('link_url', ASCENDING)], unique=True)
        self.PhRes.create_indexes([idx])
        # if your existing DB has duplicate records, refer to:
        # https://stackoverflow.com/questions/35707496/remove-duplicate-in-mongodb/35711737 
开发者ID:levphon,项目名称:pornhubbot,代码行数:10,代码来源:pipelines.py


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