/** * @param string $namespace */ private function _dbToFileMongo($namespace) { $mongo = CM_Service_Manager::getInstance()->getMongoDb(); $collectionList = \Functional\select($mongo->listCollectionNames(), function ($collection) use($namespace) { return preg_match('/^' . strtolower($namespace) . '_/', $collection); }); sort($collectionList); $optionsValid = ['unique', 'name', 'dropDups', 'sparse', 'expireAfterSeconds']; $indexes = []; foreach ($collectionList as $collection) { $indexList = $mongo->getIndexInfo($collection); foreach ($indexList as $indexInfo) { $key = $indexInfo['key']; $options = array_intersect_key($indexInfo, array_flip($optionsValid)); $indexes[$collection][] = ['key' => $key, 'options' => $options]; } } $dump = CM_Params::jsonEncode($indexes, true); $dirPath = CM_Util::getModulePath($namespace) . '/resources/mongo/'; CM_File::getFilesystemDefault()->ensureDirectory($dirPath); CM_File::create($dirPath . 'collections.json', $dump); }