async def setup(self):
        """Setting up MongoDB collections, if they not exist."""
        try:
            db = await self.db
            collections = await db.list_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 and 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
async def setup ( self ) : try : db = await self . db collections = await db . list_collection_names ( ) created = False if self . table_name not in collections : 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 if self . control_table_name and self . control_table_name not in collections : 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
Setting up MongoDB collections, if they not exist.