storage2.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码
def _ensure_index(self):
        """
        Ensure indices for all databases and collections.

        first access self._dbs config to get index column names;
        then get collection names from self._collNames and loop
        over all collections.

        """
        if self._collNames and self._dbs:
            try:
                for dbName in self._dbs:
                    # Iterate over database configurations.

                    db = self._dbs[dbName]
                    dbSelf = db['self']
                    index = db['index']
                    collNames = self._collNames[db['collNames']]
                    # db['self'] is the pymongo.Database object.

                    for name in collNames:
                        coll = dbSelf[name]
                        coll.ensure_index([(index, 
                                            pymongo.DESCENDING)], unique=True)
                print '[MONGOD]: MongoDB index set.'
                return 1
            except KeyError:
                msg = '[MONGOD]: Unable to set collection indices; ' + \
                      'infomation in Config.body["dbs"] is incomplete.'
                raise VNPAST_DatabaseError(msg)
            except Exception, e:
                msg = '[MONGOD]: Unable to set collection indices; ' + str(e)
                raise VNPAST_DatabaseError(msg)

    #----------------------------------------------------------------------
    # Download method.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号