Python pymongo.HASHED Examples

The following are 5 code examples of pymongo.HASHED(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pymongo , or try the search function .
Example #1
Source File: _ndarray_store.py    From arctic with GNU Lesser General Public License v2.1 6 votes vote down vote up
def _ensure_index(collection):
        try:
            collection.create_index([('symbol', pymongo.HASHED)], background=True)
            # We keep it only for its uniqueness
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('sha', pymongo.ASCENDING)], unique=True, background=True)
            # TODO: When/if we remove the segments->versions pointers implementation and keep only the forward pointers,
            #       we can remove the 'parent' from the index.
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('parent', pymongo.ASCENDING),
                                     ('segment', pymongo.ASCENDING)], unique=True, background=True)
            # Used for efficient SHA-based read queries that have index ranges
            collection.create_index([('symbol', pymongo.ASCENDING),
                                     ('sha', pymongo.ASCENDING),
                                     ('segment', pymongo.ASCENDING)], unique=True, background=True)
        except OperationFailure as e:
            if "can't use unique indexes" in str(e):
                return
            raise 
Example #2
Source File: chunkstore.py    From arctic with GNU Lesser General Public License v2.1 5 votes vote down vote up
def _ensure_index(self):
        self._symbols.create_index([(SYMBOL, pymongo.ASCENDING)],
                                   unique=True,
                                   background=True)

        self._collection.create_index([(SYMBOL, pymongo.HASHED)],
                                      background=True)
        self._collection.create_index([(SYMBOL, pymongo.ASCENDING),
                                       (SHA, pymongo.ASCENDING)],
                                      unique=True,
                                      background=True)
        self._collection.create_index([(SYMBOL, pymongo.ASCENDING),
                                       (START, pymongo.ASCENDING),
                                       (END, pymongo.ASCENDING),
                                       (SEGMENT, pymongo.ASCENDING)],
                                      unique=True, background=True)
        self._collection.create_index([(SYMBOL, pymongo.ASCENDING),
                                       (START, pymongo.ASCENDING),
                                       (SEGMENT, pymongo.ASCENDING)],
                                      unique=True, background=True)
        self._collection.create_index([(SEGMENT, pymongo.ASCENDING)],
                                      unique=False, background=True)
        self._mdata.create_index([(SYMBOL, pymongo.ASCENDING),
                                  (START, pymongo.ASCENDING),
                                  (END, pymongo.ASCENDING)],
                                 unique=True, background=True) 
Example #3
Source File: mongomodelstore.py    From aurum-datadiscovery with MIT License 5 votes vote down vote up
def init(dataset_name, create_index=True):
    # Connection to DB system
    global dbc
    dbc = MongoClient(C.db_location)
    # Configure right DB
    global database
    database = dbc[dataset_name]
    global modeldb
    modeldb = database.columns
    # Create full text search index
    if create_index:
        print("Creating full-text search index")
        modeldb.create_index([('t_data', TEXT)])
        modeldb.create_index([("key", HASHED)]) 
Example #4
Source File: indexes.py    From umongo with MIT License 5 votes vote down vote up
def explicit_key(index):
    if isinstance(index, (list, tuple)):
        assert len(index) == 2, 'Must be a (`key`, `direction`) tuple'
        return index
    if index.startswith('+'):
        return (index[1:], ASCENDING)
    if index.startswith('-'):
        return (index[1:], DESCENDING)
    if index.startswith('$'):
        return (index[1:], TEXT)
    if index.startswith('#'):
        return (index[1:], HASHED)
    return (index, ASCENDING) 
Example #5
Source File: mongostorage.py    From steemdata-mongo with MIT License 4 votes vote down vote up
def ensure_indexes(self):
        self.Blockchain.create_index('previous', unique=True)
        self.Blockchain.create_index('block_id', unique=True)
        self.Blockchain.create_index([('block_num', -1)])

        self.Accounts.create_index('name', unique=True)

        # Operations are using _id as unique index
        self.Operations.create_index([('type', 1), ('timestamp', -1)])
        self.Operations.create_index([('block_id', 1)])
        self.Operations.create_index([('type', 1)])
        self.Operations.create_index([('block_num', -1)])
        self.Operations.create_index([('timestamp', -1)])
        # partial indexes
        self.Operations.create_index([('author', 1), ('permlink', 1)], sparse=True, background=True)
        self.Operations.create_index([('to', 1)], sparse=True, background=True)
        self.Operations.create_index([('from', 1)], sparse=True, background=True)
        self.Operations.create_index([('memo', pymongo.HASHED)], sparse=True, background=True)

        # AccountOperations are using _id as unique index
        self.AccountOperations.create_index([('account', 1), ('type', 1), ('timestamp', -1)])
        self.AccountOperations.create_index([('account', 1), ('type', 1)])
        self.AccountOperations.create_index([('account', 1)])
        self.AccountOperations.create_index([('type', 1)])
        self.AccountOperations.create_index([('timestamp', -1)])
        self.AccountOperations.create_index([('index', -1)])

        self.Posts.create_index([('author', 1), ('permlink', 1)], unique=True)
        self.Posts.create_index([('identifier', 1)], unique=True)
        self.Posts.create_index([('author', 1)])
        self.Posts.create_index([('created', -1)])
        self.Posts.create_index([('json_metadata.app', 1)], background=True, sparse=True)
        self.Posts.create_index([('json_metadata.users', 1)], background=True, sparse=True)
        self.Posts.create_index([('json_metadata.tags', 1)], background=True, sparse=True)
        self.Posts.create_index([('json_metadata.community', 1)], background=True, sparse=True)
        self.Posts.create_index([('body', 'text'), ('title', 'text')], background=True)

        self.Comments.create_index([('identifier', 1)], unique=True)
        self.Comments.create_index([('parent_author', 1)])
        self.Comments.create_index([('parent_permlink', 1)])
        self.Comments.create_index([('author', 1)])
        self.Comments.create_index([('permlink', 1)])
        self.Comments.create_index([('created', -1)])
        self.Comments.create_index([('body', 'text'), ('title', 'text')], background=True)

        self.PriceHistory.create_index([('timestamp', -1)])

        # 4 jesta's tools
        self.Operations.create_index(
            [('producer', 1), ('type', 1), ('timestamp', 1)],
            sparse=True, background=True)
        self.Operations.create_index(
            [('curator', 1), ('type', 1), ('timestamp', 1)],
            sparse=True, background=True)
        self.Operations.create_index(
            [('benefactor', 1), ('type', 1), ('timestamp', 1)],
            sparse=True, background=True)
        self.Operations.create_index(
            [('author', 1), ('type', 1), ('timestamp', 1)],
            sparse=True, background=True)