src/Webiny/AnalyticsDb/AnalyticsDb.php
private function createCollections()
    {
        $collections = $this->mongo->listCollections();

        $collectionsCreated = false;
        foreach ($collections as $collection) {
            /* @var $collection CollectionInfo */
            if ($collection->getName() == self::ADB_STATS_DAILY) {
                $collectionsCreated = true;
                break;
            }
        }

        if (!$collectionsCreated) {

            // create collections
            $this->mongo->createCollection(self::ADB_STATS_DAILY);
            $this->mongo->createCollection(self::ADB_STATS_MONTHLY);
            $this->mongo->createCollection(self::ADB_DIMS);

            // ensure indexes
            $this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_DAILY,
                new CompoundIndex('entityTsAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_MONTHLY,
                new CompoundIndex('entityMonthAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
        }
    }
private function createCollections()
    {
        $collections = $this->mongo->listCollections();

        $collectionsCreated = false;
        foreach ($collections as $collection) {
            /* @var $collection CollectionInfo */
            if ($collection->getName() == self::ADB_STATS_DAILY) {
                $collectionsCreated = true;
                break;
            }
        }

        if (!$collectionsCreated) {

            // create collections
            $this->mongo->createCollection(self::ADB_STATS_DAILY);
            $this->mongo->createCollection(self::ADB_STATS_MONTHLY);
            $this->mongo->createCollection(self::ADB_DIMS);

            // ensure indexes
            $this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_DAILY,
                new CompoundIndex('entityTsAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_MONTHLY,
                new CompoundIndex('entityMonthAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
        }
    }
private function createCollections ( ) { $ collections = $ this -> mongo -> listCollections ( ) ; $ collectionsCreated = false ; foreach ( $ collections as $ collection ) { /* @var $collection CollectionInfo */ if ( $ collection -> getName ( ) == self :: ADB_STATS_DAILY ) { $ collectionsCreated = true ; break ; } } if ( ! $ collectionsCreated ) { // create collections $ this -> mongo -> createCollection ( self :: ADB_STATS_DAILY ) ; $ this -> mongo -> createCollection ( self :: ADB_STATS_MONTHLY ) ; $ this -> mongo -> createCollection ( self :: ADB_DIMS ) ; // ensure indexes $ this -> mongo -> createIndex ( self :: ADB_STATS_DAILY , new CompoundIndex ( 'entityTsEntry' , [ 'entity' , 'ref' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_DAILY , new CompoundIndex ( 'entityTsAttrEntry' , [ 'entity' , 'ts' , 'attributes.name' , 'attributes.value' ] , false , false ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_MONTHLY , new CompoundIndex ( 'entityMonthEntry' , [ 'entity' , 'ref' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_MONTHLY , new CompoundIndex ( 'entityMonthAttrEntry' , [ 'entity' , 'ts' , 'attributes.name' , 'attributes.value' ] , false , false ) ) ; $ this -> mongo -> createIndex ( self :: ADB_DIMS , new CompoundIndex ( 'dimension' , [ 'name' , 'value' , 'entity' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_DIMS , new CompoundIndex ( 'dimension_entity' , [ 'entity' , 'ts' ] , true ) ) ; } }
Creates the necessary indexes and collections if they don't exist.
Creates the necessary indexes and collections if they don t exist .