mongo.py 文件源码

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

项目:livebridge 作者: dpa-newslab 项目源码 文件源码
def setup(self):
        """Setting up MongoDB collections, if they not exist."""
        try:
            db = await self.db
            collections = await db.collection_names()
            created = False
            if self.table_name not in collections:
                # create table
                logger.info("Creating MongoDB collection [{}]".format(self.table_name))
                await db.create_collection(self.table_name)
                await db[self.table_name].create_index([("target_id", DESCENDING), ("post_id", DESCENDING)])
                created = True
            # create control collection if not already created.
            if self.control_table_name not in collections:
                # create table
                logger.info("Creating MongoDB control data collection [{}]".format(self.control_table_name))
                await db.create_collection(self.control_table_name)
                created = True
            return created
        except Exception as exc:
            logger.error("[DB] Error when setting up MongoDB collections: {}".format(exc))
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号